I need to find the maximum test score from an input file of test scores. The test scores are listed as percentages, one per line in the text file. I'm just not sure how to go about doing so. Right now my program just reads in the numbers and assigns them a letter grade.
I'm thinking I can assign the numbers to an array, but if there is a way to do this without using arrays I would prefer that.
string grade (double g) {
string p;
if (g >= 90) {
p = "A";
}
if (g >= 80 && g < 90) {
p = "B";
}
if (g >= 70 && g < 80) {
p = "C";
}
if (g >= 60 && g < 70) {
p = "D";
}
if (g < 60) {
p = "F";
}
return p;
}
int main() {
ifstream inData;
try {
inData.open("Scores.txt");
}
catch (int e) {
return -1;
}
cout << "Percentage" << " " << "Grade" << endl;
cout << "-------------------" << endl;
while (!inData.eof()) {
double g;
inData >> g;
string p;
p = grade (g);
cout << " " << g << "%" << " -- " << p << endl;
}
}