I am trying to find the average for the 10 different integer input from user and then to fine numbers above the average and below the average, I dont know what is wrong the code below executes and i am able to input 10 different integer but after that the program exits I am not able to see what it executes can anyone help within this.

#include <iostream>

using namespace std;

void numav(int *arg);

int main()
{
int *array = new int[10];

for(int i=0; i<10; i++)
{
cout<<"Enter number "<<(i+1)<<endl;
cin>>array;
}

numav(array);

return 0;
system("PAUSE");
return EXIT_SUCCESS;

}

void numav(int *arg)
{
float x = 0;
int y = 0;

for(int i=0;i < 10; i++)
{
x +=arg;
}

x /=10;
for(int i=0;i < 10; i++)
{
if (x<arg)
y++;
}

cout<<endl<<"The average is:"<<x<<endl<<"The number above the average is:"<<y;
}

Recommended Answers

All 3 Replies

You have this :

return 0;
system("PAUSE");
return EXIT_SUCCESS;

Take out the return 0 , since return EXIT_SUCCESS is the same thing.

So you should now have this :

system("PAUSE");
return EXIT_SUCCESS;

For finding the average do..

int average = 0;

for(int i=0; i<10; i++)
{
     cout<<"Enter number " <<endl;
     cin>>array[i];
}

for (int i = 0; i < 10; i++)
{
     average += array[i];
}

average = average / 10;

For finding values above or below the average...

for (int i = 0; i < 10; i++)
{
      if (array[i] > average)
            cout << array[i];    // Print out values larger than the average
      else
            cout << array[i];  // Print out values less than the average
}

I want to find numbers below the average can you help me finding that? btw thanks for the help.


You have this :

return 0;
system("PAUSE");
return EXIT_SUCCESS;

Take out the return 0 , since return EXIT_SUCCESS is the same thing.

So you should now have this :

system("PAUSE");
return EXIT_SUCCESS;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.