Reading a text file & doing mathematical operations with it's contents

Among my c++ manual exercices, there is one that asks me to open a text file, read it's contents which look like this:

2.776667
7.34532
3.00463
1.95678
-1.69857
1.36679

followed by at least 20 more numbers in that manner.

The exercice asks me to calculate the sum, average, lowest number, highest number and print the results.

We haven't learned about arrays in class yet, only the "for, while" loops.

My idea was to do something like this:

int number;
int sum=0;
int counter=0;
int maxCounter=100;

while (counter<maxCounter)
{
sum += number;
counter++;

}

However my problem resides in the fact that I don't know how to get to the next number once the first number is added to the sum.

For the average it would probably be something like: average = sum / counter;
Where the counter would start at the first number, and when it goes through all the numbers it would stop (which means the counter is equal the number of numbers we added up)

For the highest/lowest number, I really can't think of a solution no matter how much I think about it. I would also like to know if there is a way to go through all the numbers without knowing how many numbers the text file contains and then stops once all numbers are added up. ( I know there are 30 numbers, so I can set the maxCounter to 50, but if I have no idea? )

I appologize for my poor english as it is not my native language.
Topic archived. No new replies allowed.