ifstream in_gradebook;
ofstream out_gradebook;
in_gradebook.open("gradeBook.txt");
out_gradebook.open("gradeBook_edit.txt");
while (???) //while int is being read
{
in_gradebook >> score;
out_gradebook << score << " ";
sum = sum + score;
}
average = sum / 10.0;
out_gradebook << average << endl;
Here is a small snippet of the code I have trouble with.
My professor told me there's a way to end the loop when the input from in_gradebook is no longer type int, which I have no idea how to do. Basically, my loop goes on forever because the variable score gets the string FIRST_NAME_2 of the second line. What is a good way to end the loop when there are no more numbers to input?
The input file goes something like this:
FIRST_NAME LAST_NAME 1 2 3 4 5 6 7 8 9
FIRST_NAME_2 LAST_NAME_2 1 2 3 4 5 6 7
As you can see I am only a beginner :$, I apologize beforehand if I do not understand replies that may be beyond my level.