Problem with code segment

The following code segment is supposed to output the average of the five numbers on each output line, for all the lines in the file. Instead it outputs the sum of all of the numbers in the file.

How do I fix it to work correctly?

sum = 0;
while (indata)
{
count = 1;
while (count <= 5 && indata)
{
cin >> number;
sum = sum + number;
}
cout << sum / count << endl;
}
You never increment count, so it will be one at the end of the loop.
I'm not really sure I know what you mean. Are you saying that count = 1 shouldn't be where it is??
Ok, think about it this way:

Before your while loop, count is 1. What is count after the while loop?
just a hint, you can increase a int variable by putting ++ after the variable
@MicMagicFly: The way you have it now, if you read in 1 number from the text file, count=1. If you read in 5 numbers from the text file, count=1 (it should be 5).
sorry dismiss my reply, i misunderstood something ;)
Hi liero....are you saying that count should read 5 instead of 1? I'm very new at this and really don't understand the whole 'while loop' thing.
Topic archived. No new replies allowed.