### While-Loop Help

Below is code that reads in student last and first names, various scores and calculates their averages. The first line of the input file is the key that gives max point values for each assignment. I can't seem to get the average to calculate once it starts listing student's, and for some reason it outputs the last student's info twice and then breaks the loop. Any help would be much appreciated.

the input file looks something like:
"Key Key 10 10 10 10 20 20 20 20 100 100

Washingtonian George 10 10 -1 10 20 -1 -1 20 100 80

Doe Jane -1 -1 -1 -1 -1 -1 -1 -1 -1 -1"

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113`` `````` studentNum = 0; key = true; maxPoints = 0; while (inFile) { quizNum = 0; quizSum = 0; hwNum = 0; hwSum = 0; examNum = 0; examSum = 0; if ( key == true) { inFile >> first; while (quizNum < 4) { inFile >> quiz; quizSum += quiz; quizNum++; } while (hwNum < 4) { inFile >> hw; hwSum += hw; hwNum++; } while (examNum < 2) { inFile >> exam; examSum += exam; examNum++; } maxPoints = quizSum + hwSum + examSum; average = (maxPoints/maxPoints)*100; outFile << left << setw(3) << " " << left << setw(12) << last << left << setw(7) << first; outFile << left << setw(6) << quizSum << left <> last >> first; studentNum++; while (quizNum < 4) { inFile >> quiz; if (quiz < 0) { quiz = 0; } quizSum += quiz; quizNum++; } while (hwNum < 4) { inFile >> hw; if (hw < 0) { hw=0; } hwSum += hw; hwNum++; } while (examNum < 2) { inFile >> exam; if (exam < 0) { exam = 0; } examSum += exam; examNum++; } points = quizSum + hwSum + examSum; average = (points/maxPoints)*100; outFile << left << setw(3) << studentNum << left << setw(12) << last.substr(0,10) << left << setw(7) << first.substr(0,5); outFile << left << setw(6) << quizSum << left <

output is :
 ```# Last First Quiz HW Exam Total Average - ---------- ----- ---- --- ---- ----- ------- Key Key 40 80 200 320 100.00 - ---------- ----- ---- --- ---- ----- ------- 1 Washington Georg 30 40 180 250 0.00 2 Doe Jane 0 0 0 0 0.00 3 Doe Jane 0 0 0 0 0.00 ```
Last edited on
Topic archived. No new replies allowed.