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;
}
@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).