I have a file that contains 20 names and scores. I need to read them into a struct then find the letter grade for each student and the highest grade. Haven't gotten to the highest grade one yet. I am getting confused quick, thought this was going to be easy but I was wrong. Insight from you guy always clears me up =D I am just confused on how to create the struct then put an array inside of it and then read the file into it. Here is what I have so far:
ERRORS:
1>c:\users\welcome back\documents\visual studio 2008\projects\struct\struct\structs.cpp(35) : error C2182: 'printOut' : illegal use of type 'void'
1>c:\users\welcome back\documents\visual studio 2008\projects\struct\struct\structs.cpp(35) : error C2078: too many initializers
1>c:\users\welcome back\documents\visual studio 2008\projects\struct\struct\structs.cpp(45) : error C2082: redefinition of formal parameter 'sList'
1>c:\users\welcome back\documents\visual studio 2008\projects\struct\struct\structs.cpp(45) : error C2601: 'sList' : local function definitions are illegal
1> c:\users\welcome back\documents\visual studio 2008\projects\struct\struct\structs.cpp(43): this line contains a '{' which has not yet been matched
1>c:\users\welcome back\documents\visual studio 2008\projects\struct\struct\structs.cpp(50) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
struct studentType
{
string studentFName;
string studentLName;
int testScore;
char grade;
};
void getData (ifstream& inFile, studentType sList[], int size);
void calcGrade (studentType sList[], int size);
//int highScore (const studentType sList[], int size);
void printOut (ofstream& outFile, const studentType sList[], int size);
int main() {
ifstream inp;
ofstream outp;
inp.open("C:\\Users\\Welcome Back\\Desktop\\Ch11_Ex01Data.txt");
outp.open("C:\\Users\\Welcome Back\\Desktop\\Ch11_Ex01Out.txt");
studentType sList[20];
int size;
void printOut(outp, sList, size);
return 0;
}
void getData(ifstream& inp, studentType& sList, int size)
{
struct studentType sList[20]
{
string studentFName;
string studentLName;
int testScore;
char grade;
}
for (size = 0; size < 20; size++)
{
infile >> sList[size].studentFName
>> sList[size].studentLName
>> sList[size].testScore;
}
calcGrade(sList, size);
}
void calcGrade(studentType& sList, int size)
{
for (size = 0; size < 20; size++)
{
if (sList[size].testScore >= 90)
sList.grade = 'A';
else if (sList[size].testScore >= 80)
sList.grade = 'B';
else if (sList[size].testScore >= 70)
sList.grade = 'C';
else if (sList[size].testScore >= 60)
sList.grade = 'D';
else
sList.grade = 'F';
}
}
void printOut(ofstream& outp, studentType& sList, int size)
{
getData(inp, sList, size);
for (size = 0; size <20; size++)
{
outp << sList[size].studentLName << ", " << sList[size].studentFName << ", " << sList[size].testScore << ", " << sList[size].grade << endl;
}
}
ERRORS:
1>c:\users\welcome back\documents\visual studio 2008\projects\struct\struct\structs.cpp(35) : error C2182: 'printOut' : illegal use of type 'void'
1>c:\users\welcome back\documents\visual studio 2008\projects\struct\struct\structs.cpp(35) : error C2078: too many initializers
1>c:\users\welcome back\documents\visual studio 2008\projects\struct\struct\structs.cpp(45) : error C2082: redefinition of formal parameter 'sList'
1>c:\users\welcome back\documents\visual studio 2008\projects\struct\struct\structs.cpp(45) : error C2601: 'sList' : local function definitions are illegal
1> c:\users\welcome back\documents\visual studio 2008\projects\struct\struct\structs.cpp(43): this line contains a '{' which has not yet been matched
1>c:\users\welcome back\documents\visual studio 2008\projects\struct\struct\structs.cpp(50) : fatal error C1903: unable to recover from previous error(s); stopping compilation