Function highestScore has several problems.
a) a variable is used which has the same name as the function itself. Change the variable name to something else.
b) the function should return a value. It has no return statement.
c) the prototype declared on line 22 uses a different number of parameters to the function definition further down.
d) it's hard to tell because of the lack of indentation, but it looks like this function has no closing brace.
The definition of function printResult has a semicolon, which should not be there.
int highestScore (const studentType sList[], int listSize)
{
int max = sList[0].grade;
for (int i = 0; i < listSize; i++) {
if (sList[i].grade > max)
max = sList[i].grade;
}
return max;
}
void printResult(const studentType sList[], int listSize){
ofstream outFile("Ch9_Ex2Out.txt");
string name = "";
outFile << left << setw(30) << "Student Name" << right << setw(10) << "Test Score" << right << setw(7) << "Grade" << endl;
for (int i = 0; i < listSize; i++){
name = sList[i].studentLName + ", " + sList[i].studentFName;
outFile << left << setw(30) << name << right << setw(10) << sList[i].testScore << right << setw(7) << sList[i].grade << endl;
}
outFile << endl;
int highscore = highestScore(sList, listSize);
outFile << "Highest Test Score: " << highscore << endl;
outFile << "Students having the highest test score: " << endl;
for (int i = 0; i < listSize; i++){
if ( sList[i].testScore == highscore ){
outFile << sList[i].studentLName << ", " << sList[i].studentFName << endl;
}
}
Although when I compile everything and there are no errors nor warnings, the output doesn't give me anything!
While we are on the topic of errors and warnings, what happens if either the input or output file is not opened successfully?
You should always as a matter of routine check for successful opening of files. Use file.good() or file.is_open() to check for this condition.
If there's a problem, output a useful message to show what went wrong, and exit.
A different topic. Function highestScore()
Here you assign char grade to int max. I think that is a mistake.