Error ID returned 1 exit status -HELP

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

const int NO_OR_STUDENTS = 20;

struct studentType
{
string studentFName;
string studentLName;
int testScore;
char grade;
}; // bug1 missing ;

void getData(ifstream& inFile, studentType sList[], int listSize);
void calculateGrade(studentType sList[], int listSize);
void printResult(ofstream& outFile, const studentType sList[], int listSize);
void holdscreen( string exitMessage );

int main()
{
ifstream inData;
ofstream outData;
studentType studentList[NO_OR_STUDENTS];

cout << "\nThis program gets student names and test scores from one file "
<< "and writes a report to another file. \n\n";

inData.open("T3DebugData.txt"); //bug5 "Debug" misspelled

if (!inData)
{
cout << "The input file does not exist. Program terminates!"
<< endl;
holdscreen ("Error Exit - Input file error!");
return 1;
}

outData.open("T3DebugOut.txt");
if (!outData)
{
cout << "Cannot open the output file. Program terminates!"
<< endl;
holdscreen ("Error Exit - Output file error!");
return 1;
}

getData(inData, studentList, NO_OR_STUDENTS);
calculateGrade(studentList, NO_OR_STUDENTS);
printResult(outData, studentList, NO_OR_STUDENTS);

holdscreen ("All the scores have been processed!");

return 0;
}

void getData(ifstream& inFile, studentType sList[], int listSize)
{
for (int i = 0; i < listSize; i++)
inFile >> sList[i].studentFName >> sList[i].studentLName
>> sList[i].testScore;
return;
}

void calculateGrade(studentType sList[], int listSize)
{
for (int i = 0; i < listSize; i++)
{
switch (sList[i].testScore / 10)
{
case 10:
case 9:
sList[i].grade = 'A';
break;
case 8:
sList[i].grade = 'B';
break;
case 7:
sList[i].grade = 'C';
break;
case 6:
sList[i].grade = 'D';
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
sList[i].grade = 'F';
}
}
return;
}

int highestScore(const studentType sList[], int listSize)
{
int hScore = sList[0].testScore;

for (int i = 1; i < listSize; i++)
if (hScore < sList[i].testScore)
hScore = sList[i].testScore;

return hScore;
}

void printResult(ofstream& outFile, const studentType sList[])
{
int listSize;
int maxScore = highestScore(sList, listSize); //bug2 listsize not declared
int i;

outFile << setw(15) << "Student Name " //bug3 iomanip not included
<< setw(10) << "Test Score"
<< setw(7) << "Grade" << endl;

for (i = 0; i < listSize; i++)
outFile << left << setw(25) //bug4 f not capitalized in outFile
<< sList[i].studentLName + ", " + sList[i].studentFName
<< right << " " << setw(5) << sList[i].testScore
<< setw(6) << " " << sList[i].grade << endl;

outFile << endl << "Highest Test Score: " << maxScore << endl;
outFile << "Students having the highest test score:" << endl;

for (i = 0; i < listSize; i++)
if (sList[i].testScore == maxScore)
outFile << sList[i].studentLName + ", " + sList[i].studentFName
<< endl;
return;
}

void holdscreen( string exitMessage )
{
char holdscr = 0;
cout << "\n\n\t * * * " << exitMessage << " * * *"
<< "\n\n\t Enter a character and return to exit the program! ";
cin >> holdscr;
return;
}
Last edited on
closed account (18REwA7f)
What kind of error does your program say?
undefined reference to `printResult(std::basic_ofstream<char, std::char_traits<char> >&, studentType const*, int)'

[Error] ld returned 1 exit status


That is what it is giving me
printResult
1. function prototype declaration:
 
void printResult(ofstream& outFile, const studentType sList[], int listSize);


2. Function definition:
1
2
void printResult(ofstream& outFile, const studentType sList[])
{

The last parameter int listSize is missing from the function header. Put that in so that the prototype and main definition agree and the '[Error] ld returned 1 exit status' should be fixed.
Topic archived. No new replies allowed.