I have to write this program that reads from a file. The file contains a first name, last name, and an unspecified number of grades. I have to display the last name, first initial followed by the average.
Right now, I'm just trying to get my loops working, but I am running into an infinite loop. I can't seem to get it to stop looping at the eof. I'm just kind of testing out the looping structure so far. I haven't actually written any of the calculation code yet.
I was just going to try printing the file out as it is to test to see if I had it right, but when it gets to the end it starts printing out infinite 0's.
Why is it printing 0s instead of terminating the program? Here is an example of the test file:
John Doe 70 80
Steve Smith 55 85 95
Bill Thomas 80 85
char next = 'a';
while(next != '\n')
cout << next;
next = '1'; //I put this is so next isn't the newline char and will continue
What I was doing above was just a test to get my loops working correctly. I have to do more than just print it out.
I can't do it that way because I need to capture the names and grades into separate variables. We are only allowed to use topics we have covered so far in class, and we haven't covered any kind of string parsing yet, so I couldn't get the names and grades from the string.
The no newline after the last line of the file is helpful. Thanks for that. I will go play with my code some more.