The program for my class needs to return the average score, the high score with first and last name as well as the low score. I get an error for the functions that find the names for the high and low score and I'm not sure what the issue is.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
float highestVal(float highScore, float score);
float lowestVal(float lowScore, float score);
string highFirstFun(float highScore, float score, string firstNameHigh);
string highLastFun(float highScore, float score, string lastNameHigh);
string lowFirstFun(float lowScore, float score, string firstNameLow);
string lowLastFun(float lowScore, float score, string lastNameLow);
int main() {
ifstream inFile;
string fileName = "", firstName = "", lastName = "";
float score, average;
float highScore = 0;
float lowScore = 100;
float studentNum = 0;
float sum = 0;
int i;
string highFirst = "", highLast = "";
string lowFirst = "" , lowLast = "";
cout << "Please enter the input file name: ";
cin >> fileName;
inFile.open(fileName);
while (!inFile.is_open()) {
cout << "Sorry, the file did not open. \nTry again, or type \"cancel\" to quit: ";
cin >> fileName;
if (fileName == "cancel") {
cout << "Cancelling..." << endl;
break;
}
else {
inFile.open(fileName);
}
}
if (inFile.is_open()) {
cout << "The scores are as follows: \n";
while (!inFile.eof()) {
inFile >> firstName >> lastName >> score;
cout << firstName << " " << lastName << " scored " << score << endl;
sum += score;
studentNum++;
highScore = highestVal(highScore, score);
lowScore = lowestVal(lowScore, score);
highFirst = highFirstFun(highScore, score, firstName);
highLast = highLastFun(highScore, score, lastName);
lowFirst = lowFirstFun(highScore, score, firstName);
lowLast = lowLastFun(highScore, score, lastName);
}
average = (sum / studentNum);
cout << "There are " << studentNum << " students with an average grade of " << average << endl;
cout << "The high score was: " << highScore << " from " << highFirst << " " << highLast << endl;
cout << "The low score was: " << lowScore << " from " << lowFirst << " " << lowLast << endl;
inFile.close();
}
return 0;
}
float highestVal(float highScore, float score)
{
if (score > highScore) {
highScore = score;
}
return (highScore);
}
float lowestVal(float lowScore, float score)
{
if (score < lowScore) {
lowScore = score;
}
return (lowScore);
}
string highFirstFun(float highScore, float score, string firstNameHigh)
{
if (score > highScore) {
return (firstNameHigh);
}
}
string highLastFun(float highScore, float score, string lastNameHigh)
{
if (score > highScore) {
return (lastNameHigh);
}
}
string lowFirstFun(float lowScore, float score, string firstNameLow)
{
if (score < lowScore) {
return (firstNameLow);
}
}
string lowLastFun(float lowScore, float score, string lastNameLow)
{
if (score < lowScore) {
return (lastNameLow);
}
}
Here is the Text File that it is pulling from called "Scores.txt":
John Smith 99.0
Sarah Johnson 85.0
Jim Robinson 70.0
Mary Anderson 100.0
Michael Jackson 92.0
Any help would be much appreciated!