
November 24th, 2012, 07:56 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 2
Time spent in forums: 1 h 9 sec
Reputation Power: 0
|
|
|
C++ Compiler Error, Help Needed
The errors I'm getting are:
1) error: 'highestScore' cannot be used as a function:
int highestScore = scores[0];
2) error: 'outFile' was not declared in this scope:
outFile << setw(15) << "Student Name"
3) error: expected '}' at end of input:
outFile << sList[i].studentLName + ", " + sList[i].studentFName << endl;
}
}
Can someone figure out what the problem is?
覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧 覧覧覧覧覧覧覧
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
const int STUDENTS = 20;
struct studentType
{
string studentFName;
string studentLName;
int testScore;
char grade;
};
void getData(ifstream& inFile, studentType sList[], int listSize);
void calculateGrade(studentType sList[], int listSize);
int highestScore(const studentType sList[], int listSize);
void printResult(ofstream& outFile, const studentType sList[], int listSize);
int main()
{
ifstream inData;
ofstream outData;
studentType studentList[STUDENTS];
inData.open("Ch9_Ex2Data.txt");
if (!inData)
{
cout << "Input file does not exist."
<< endl;
return 1;
}
outData.open("Ch9_Ex2Out.txt");
if (!outData)
{
cout << "Cannot open the output file."
<< endl;
return 1;
}
getData(inData, studentList, STUDENTS);
calculateGrade(studentList, STUDENTS);
printResult(outData, studentList, STUDENTS);
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;
}
void calculateGrade(studentType sList[], int listSize)
{
int score;
for (int i = 0; i < listSize; i++)
if (score >= 90)
sList[i].testScore = 'A';
else if (score >= 80)
sList[i].testScore = 'B';
else if (score >= 70)
sList[i].testScore = 'C';
else if (score >= 60)
sList[i].testScore = 'D';
else
sList[i].testScore = 'F';
}
int highestScore(const studentType sList[], int scores[], int listSize)
{
int highestScore = scores[0];
for (int i = 0; i < listSize; i++)
{
if (scores[i] > highestScore)
{
highestScore = scores[i];
}
}
void printResult(ofstream& outFile, const studentType sList[], int listSize);
{
int maxScore = highestScore(sList, listSize);
int i;
outFile << setw(15) << "Student Name"
<< setw(10) << "Test Score"
<< setw(7) << "Grade" << endl;
for (i = 1; i < listSize; i++)
{
outFile << left << setw(25)
<< 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 = 1; i < listSize; i++)
{
if (sList[i].testScore == maxScore)
outFile << sList[i].studentLName + ", " + sList[i].studentFName << endl;
}
}
覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧 覧覧覧覧覧覧覧
|