C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 24th, 2012, 07:56 PM
ZaTaisho ZaTaisho is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 ZaTaisho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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;
}
}
覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧 覧覧覧覧覧覧覧

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > C++ Compiler Error, Help Needed


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap