list positive numbers

i stuck on b n c
A list of positive numbers is read into an array from the keyboard. The list finishes when a
number 0 is typed from the keyboard.
a. Find the average of the numbers entered
b. Print out all those below the average
c. Print out all those above the average

#include <iostream>
using namespace std;

int main()
{
int above=0,below=1,number,sum=0;
int count=0;
float average;


while(1)
{
cout<<"Enter 0 if you finished: "; cin>>number;

if(number==0)
break;

else if(number<0)
{ cout<<"\7";
cout<<"\nEnter a positive number.\n";continue;}
below=(number<below)?number:below;

sum+=number;
count++;
}

average=float(sum)/float(count);

for(count = 0;count <=average;count++);
{
if(numbers[count]>=average)
{above++;}
else
{below++;}
}
cout<<"\nYou entered " << count << " numbers."<<endl;
cout<<"Their average is : "<<average<<endl;
cout<<"Numbers above average : "<<above<<endl;
cout<<"Numbers below average : "<<below<<endl;
return 0;
}
Last edited on
If you are going to deal with positive numbers then why did you define number and sum as int instead of unsigned int?
Last edited on
You obviously can spot the above and below values and you do know each value at that moment. You could print the values with similar loops.

Correction: you don't loop correctly and your test is formally wrong too. Btw, you should use the code tags.
Topic archived. No new replies allowed.