0

Every time i compile this code i come up with a additional set of numbers, but i don't know why.

```
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
void calculateAverage(double quiz1, double quiz2, double quiz3, double
test4, double& SAverage);
int calculateGrade(double grade);
int main()
{
string studentName;
int numberOfStudents = 0;
double classAverage = 0;
double SAverage = 0;
double totalAverage = 0; //To add the average of all student averages
char grade;
double quiz1, quiz2, quiz3, quiz4;
ifstream inFile; // input stream variable for the student file
ofstream outFile; // output stream variable
inFile.open("open.txt");
cout << setfill(' ') <<setiosflags(ios:: left) << setw(11) <<
"Student" << setw(10) << "Quiz1"
<< setw(8) << "Quiz2" << setw(8) << "Quiz3" << setw(8) << "Quiz4"
<< setw(8) << "Average" << setw(8) << "Grade" <<endl;
if (!inFile)
{
cout << "Unable to open this file." <<endl;
system("PAUSE");
return 1;
}
while(inFile)
{
inFile >> studentName >> quiz1 >> quiz2 >> quiz3 >> quiz4
;
calculateAverage(quiz1, quiz2, quiz3, quiz4,SAverage);
grade = calculateGrade(SAverage);
cout << setfill(' ') << setiosflags(ios::left) << setw(11) <<
studentName << setw (10) << quiz1
<< setw(8) << quiz2 << setw(8) << quiz3 << setw(8) << quiz4
<< setw(8) << SAverage << setw(8) <<
grade<<endl;
totalAverage = totalAverage + SAverage;
numberOfStudents++;
classAverage = totalAverage / numberOfStudents;
}
inFile.close();
system("PAUSE");
return 0;
}
//function to calculate the average
void calculateAverage(double quiz1, double quiz2, double quiz3, double
quiz4, double& SAverage)
{
SAverage = double (quiz1 + quiz2 + quiz3 + quiz4) / 5.0;
}
int calculateGrade(double SAverage)
{
char grade;
if (SAverage <= 100 && SAverage >= 90)
grade = 'A';
else if (SAverage < 90 && SAverage >= 80)
grade = 'B';
else if (SAverage < 80 && SAverage >= 70)
grade = 'C';
else if (SAverage < 70 && SAverage >= 60)
grade = 'D';
else if (SAverage < 60 && SAverage >= 0)
grade = 'F';
else
cout << "Invalid grade " << endl;
return grade;
}
```

This what i get when i debug.

Student Quiz1Quiz2 Quiz3 QuizAverage Grade

70 80 90 95 95 72 C

85 90 80 75 85 66 D

70 80 55 85 50 54 F

70 45 50 40 35 34 F

70 45 50 40 35 34 F

Press any key to continue . . .

Any help will be greatly appreciated .