count the numbers below the average

Hello everyone need some help.
I have loaded and 1d array from a .dat file, calculated the average of all the numbers. Now I need to count every number in the array that is below the average and cout that number.
This is the method in the class I have so far:

int IntegerArray::countBelowAverage(int numBelowAvg)
{
avg=IntegerArray::getAvg();
for(int ct=0; ct<avg; ++ct)
{
numBelowAvg=ct;
}
return numBelowAvg;
}

My output from this is always 0 and I know that there are numbers below the avg.

Any suggestions much appreciated
Use '++' and delete '=ct' from Line 6. My guess is that the last element in you array is a '0' and at Line 6 you are setting 'numBelowAvg' to be that number then you are returning it. While you're at it, ask yourself "What's off about the argument to this member function?".
Last edited on
Computergeek01
your suggestion did not work still have the same output. could you elaberate on you question?

All I need to do is pass in the average already calulated in a different method and I have simply got tunnel vision because I can not see it.

int IntegerArray::calcAverage(int avg)
{
int sum=0;
for(int a=0;a<listCnt;++a)
{
sum+=list[a];
}
avg=sum/listCnt;
return avg;
}

this method works perfect to calculate the average.
Last edited on
Topic archived. No new replies allowed.