I am writing a homework assignment that asks for the user to read in a text file that contains an unknown number of SSNs and grades. The program then needs to compute the max, min and average scores, then output the max grade with the associated SSN as well as the min and avg grades.
It seems to operate correctly but the output is all "0".
Any help fixing this is greatly appreciated.
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
string ssn, maxSSN;
int grade = 0, totalGrades = 0, count = 0, maxScore = 0, minScore = 0;
double avgScore = 0;
ifstream inFile;
inFile.open("C:\\lab5a.txt");
if(!inFile)
{
cout << "Error opening the requested file\n\n";
system("pause");
return 101;
}
while (!inFile.eof())
{
if (count == 0)
{
maxScore = grade;
minScore = grade;
}
else
{
if (grade > maxScore)
maxScore = grade;
if (grade < minScore)
minScore = grade;
}
grade += totalGrades;
count++;
}
if (count)
avgScore = totalGrades / count;
cout << "Maximum Score: " << maxScore << " Student SSN:" << maxSSN << "\n";
cout << "Minimum Score: " << minScore << "\n";
cout << "Average Score: " << avgScore << "\n";
// studentFile >> ssn >> grade;
inFile.close();
cout << "\n\n";
system("pause");
return 0;
}