Hi, Im working on a school project and could use some help. Im having trouble storing data in an array of structs. My program has to read student data from a file and store the information in a struct.
Im having trouble passing my array struct into my fuctions, and also having trouble passing my io files into and out of the functions. Here is what i have so far.
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void Highest();
struct studentType
{
string fName, lName;
int Scores;
int Tests;
char grade;
};
studentType students[20];
void StuRead(&ifstream studentType students[]); //her i got 2 errors, error: variable or field 'StuRead' declared void
error: expected primary-expression before 'studentType'
char AssignGrade(char LetterGrade, studentType students[]);
void Print(&ofstream studentType students[]);
main ()
{
ifstream inFile;
ofstream outFile;
inFile.open("Studinfo.txt");
outFile.open("Stinfo.out");
StuRead(studentType students[]);
return 0;
}
void StuRead(&inFile studentType students[]) //on this function heading I got these 2 errors, error: variable or field 'StuRead' declared void, error: redefinition of 'int StuRead'
{
int x;
x = 0;
for (x = 1; x < 20; x++)
{
inFile >> students[x].lName
>> students[x].fName
>> students[x].Tests;
}
}
char AssignGrade(char LetterGrade, studentType students[])
{
int score, x;
score = students[x].Tests;
if(score >= 90)
studentType.grade = 'A';
else if(score >= 80)
studentType.grade = 'B';
else if(score >= 70)
studentType.grade = 'C';
else if(score >= 60)
studentType.grade = 'D';
else
studentType.grade = 'F';
//Here i got a wierd error on each line. error: expected unqualified-id before '.' token
}
void Highest(studentType students[])
{
int x;
int highTest = 0;
for(x = 0; x < 20; x++)
{
if(x > highTest)
highTest = x;
}
}
void Print(&outFile studentType students[]) //Here i got another error: outfile was not declared in this scope.
{
int x;
for(x = 0; x < 20; x++)
{
outFile << setw(10) << students[x].tests << endl;
}
}
As you can see, I outlined some of the error msges that i am getting but anything else that any1 finds wrong, please tell me, Thanks alot for the help guys! :)