probably cos it's wrong.
Post all your code.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
you probably didn't initialize totalNumber when declaring it
int totalNumber = 0;
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
All you have to do inside the loop that starts on line 23 is (1) total up the value of all the numbers read from the file, which line 30 does ok, and (2) count how many numbers are read from the file, which line 27 does. Then after the file reading is finished you need to calculate the average, which line 33 does do, but its in the wrong place in your program (move it down below line 34 so that its outside the loop). That means line 26 is completly useless, and in fact destroys the value of totalNumber accumulator, so delete line 26.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
It is true that the average calculation will work inside the loop, but its a waste of processing time to leave it there. If a teacher wants to find the average grade of all students for a given test she/he does not recalculate the average every time a student's grade is added to the total. No because that's such a waste of her time. Instead she will wait until all student's grades are summed up then divide that total by the number of students.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343