I'm trying to make the following Read from file end when it encounters -1.
however the following code continuous reading the -1 row. Does it have something to do with how i'm wording my expression? score1 != -1? (Data4 below code)
Also doyoualwayswriteyoursentenceslikethis? Notice the added whitespace in the above snippet. And since all of your variables are integral values I hope you're aware that integral math has no fractional parts.
I appreciate the lesson on white space as c++ is a program that allows me to use as much of that as i want. However the above change in while didn't help much. It actually read less of the Data4 file if anything. I am interested in what you said about integral math having no fractional parts. Do you mean remainders? If i am unaware of something in c++ i would like to be informed. :D thank you!
However the above change in while didn't help much. It actually read less of the Data4 file if anything.
Are you sure the file actually opened correctly?
The program seems to work for me:
Student # 1's average is: 90
Student # 2's average is: 85
Student # 3's average is: 76
Student # 4's average is: 89
Student # 5's average is: 90
Student # 6's average is: 91
Total class average is: 86
inputStream>>score1>>score2>>score3; (atleast i think this is redundant)
Not really redundant, but it is incorrect. By having two read statements you will skip ever other line.
Remember in the while loop you are reading the three scores, then testing the stream state for errors. If there are errors reading any of the variables the loop will end because of the failed stream. Otherwise it will check to see if score is not equal to negative one. If it is equal to negative one then the loop will terminate.
also regarding the remainders i could just used double.
If you want your averages to show fractional parts then yes double would be a good choice. And remember when doing calculations using constants at least one side of the equation must be a floating point number to force floating point math.
3 / 4 * 5.0
The above calculation will yield zero because 3 / 4 uses integer math and the result yields zero.
And please please start using whitespace to help make your code readable. Lumping everything together makes it harder for humans to read the code.