Calculate highest grades

I am creating a program that when you input a .txt and input an output file .txt also into the program the program reads which student has the highest and lowest grade and outputs those student name and last name and also there grades. My question is that I keeping getting an error stating that the st[size] function is incorrect.

javascript:txt('

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

using namespace std;

struct studentType
{
string studentFName;
string studentLName;
int testscore;
char grade;
};
void readdata(ifstream & dataIn, studentType st[], int size);

void assingReleventGrade(studentType st[], int size);

int main() {
// decaring variables

int size = 20;
struct studentType st[size]; // this is where my error is st[size]

ifstream dataIn;
ofstream dataOut;

dataIn.open("Ch9.Ex2Data.txt");
dataOut.open("output.txt");
readdata(dataIn, st, size);

// calling the function to assing the grade letter to grade
assingReleventGrade(st, size);

//writing data to output file
for (int i = 0; i < size; i++)
{
dataOut << st[i].studentLName << ","
<< st[i].studentFName << "" << st[i].testScore << ""
<< st[i].grade << endl;
}
dataIn.close();
dataOut.close();
return 0;
}
void readdata(ifstream & dataIn, studentType st[], int size)
{
string fname, lname;
int score;
int i = 0;
while (i < size)
{
dataIn >> fname >> lname >> score;
st[i].studentFName = fname;
st[i].studentLName = lname;
st[i].testscore = score;

i++;
}
}
void assignReleventGrade(studentType st[], int size)
{
for (int i = 0; i < size; i++)
{
if (st[i].testscore >= 90)
st[i].grade = 'A';
else if (st[i].testscore >= 80 && st[i].testscore < 90)
st[i].grade = 'B';
else if (st[i].testscore >= 70 && st[i].testscore < 80)
st[i].grade = 'C';
else if (st[i].testscore >= 60 && st[i].testscore < 70)
st[i].grade = 'D';
else if (st[i].testscore < 60)
st[i].grade = 'F';
}
')
Last edited on
struct studentType st[size]; // this is where my error is st[size]
When you decalre an array the size must be constant.
Are you not allowed to use a vector?
Thomas1965 how would i do that, and yes
Last edited on
Topic archived. No new replies allowed.