Hii,
I'm really bad at programming so please help me to write this program:
"A program that reads 100 numbers and calculate their average - should print numbers that are larger than the average"?
I tried, and think it is wrong and missing something(s)! :\
#include <iostream>
#define N 100
using namespace std;
int main ()
{
int n;
float avg;
cout<< "Please enter a number"<<endl;
cin>> n;
for (int count=0; count<=100; count++)
avg= count / 100;
cout<< "The average is " << avg << endl;
cin>> avg;
return 0;
}
#include <iostream>
usingnamespace std;
int main ()
{
int n;
int count=0;
int sum=0;
double avg;
cout<< "Please enter a number"<<endl;
cin>> n;
while( count<=100)
{
sum = sum + n;
cin>> n;
count++;
}
avg= sum / count;
cout<< "The average is " << avg << endl;
return 0;
}
}
Thanks!
but why when I put like 3 or 4 numbers the average always = 0?
and I should put '^' after I write the numbers for the answer to show?? like this: http://i57.tinypic.com/4kiq81.png
Ain't that swell considering all the errors in it?
deepestblue claims that ( int i=0; i<=1; ++i ) iterates 1 time. It actually iterates 2 times: i==0 and i==1.
The count is 101 after the while ( count <=100 ) ++count;
1 2 3 4 5
int sum;
int count;
double avg;
avg = sum / count;
Integer division. The sum/count is calculated as integers and the result is integer. 99/100 == 0
The unnamed temporary integer result is converted to double during assignment to avg after division has discarded reminder.