I am working on a lab problem and I feel like I pretty close. I am supposed to take in 10 numbers from the user. After that I will output several things. The part where I am stuck is displaying numbers that are above and below the calculated average. The average is fine, but I keep getting an error code on line 22 of the program.
#include<iostream>
usingnamespace std;
int main()
{
int count;
constint Size = 10;
cout << " Please enter 10 numbers: ";
int numbers[10];
int sum = 0;
int avg;
int high = 0;
int low = 0;
for (int i = 0; i < 10; i++)
{
cin >> numbers[i];
}
for (int i = 0; i < Size; i++)
sum = sum + numbers[i];
avg = sum / Size;
for (count = 0; count < numbers; count++)
{
if (numbers[count] >= avg)
high++;
else
low++;
}
cout << "\nThe third and seventh numbers are: ";
cout << numbers[2] << ", ";
cout << numbers[6] << endl;
cout << "The average is: " << sum / Size << endl;
cout << "The numbers above the average are: " << high << endl;
cout << "The numbers below the average are: " << low << endl;
return 0;
}
You're error comes from the fact that numbers is an array, so you're trying to see if an int < int*, which makes no sense. I think what you meant to put there is for (count = 0; count < Size; count++) That way you're checking to see if count is still less than the total number of elements in the numbers array rather than checking to see if count is less than the memory address of the array.