Please help with writing a program?

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"?
to make it read 100 numbers the counter=0; and counter<=100 and counter++

then the average would equal the counter / 100


try this hint and show me your result
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;
}
you haz to know av = sum/count as count will equal 100 @ last!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>

using namespace 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;
}
}
Last edited on
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
did change something??

just copy paste the solution up there!!!

each number you write then enter

don`t right them next to each other!!

you`re working on a 100 number average not 3 or 4 numbers??
Thanks it worked! ;)
welcome...:)
Thanks it worked! ;)

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.
aaaah~~ right..!!!

didn`t notice that :o i was in a hurry!!

keskiverto
Topic archived. No new replies allowed.