Expected Primary-Expression Before ‘]’ Token
Hello, I keep getting this error while trying to compile. The error occurs in lines 27, 28, and 29. Is something syntactically wrong?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
const int NUM_STUDENTS=10;
const int NUM_GRADES=10;
struct StudentInfoType
{string name;
int grades[NUM_GRADES];
float avg;
};
void getInfo(StudentInfoType student[]);
void calcAvg(StudentInfoType student[]);
void printGrades(StudentInfoType student[]);
//Main
int main()
{
StudentInfoType student[NUM_STUDENTS];
getInfo(student[]);
calcAvg(student[]);
printGrades(student[]);
return 0;
}
//getInfo
void getInfo(StudentInfoType student[])
{
string filename;
ifstream fin;
cout << "Enter filename: ";
cin >> filename;
fin.open(filename.c_str());
while(!fin)
{
fin.clear();
cerr << "The file named " << filename << " was not found.";
cout << endl << "Please enter filename: ";
cin >> filename;
fin.open(filename.c_str());
}
for(int i=0; i<NUM_STUDENTS; i++)
{
fin >> student[i].name;
for(int j=0; j<NUM_GRADES; j++)
{fin >> student[i].grades[j];}
}
}
//calcAvg
void calcAvg(StudentInfoType student[])
{
for(int i=0; i<NUM_STUDENTS; i++)
{
float total=0;
for(int j=0; j<NUM_GRADES; j++)
{total = total + student[i].grades[j];}
student[i].avg = total/NUM_GRADES;
}
}
//printGrades
void printGrades(StudentInfoType student[])
{
for(int i=0; i<NUM_STUDENTS; i++)
{
cout << setw(8) << left << setfill(' ') << student[i].name << ' ';
for (int j=0; j<NUM_GRADES; j++)
{cout << setw(4) << right << setfill(' ') << student[i].grades[j] << ' ';}
cout << setw(7) << right << setfill(' ') << fixed <<
showpoint << setprecision(2) << student[i].avg << endl;
}
}
|
Last edited on
Is something syntactically wrong? |
Yes.
1 2 3 4 5 6 7 8
|
int main()
{
StudentInfoType student[NUM_STUDENTS];
getInfo(student[]);
calcAvg(student[]);
printGrades(student[]);
/*...*/
|
should look more like
1 2 3 4 5 6 7 8
|
int main()
{
StudentInfoType student[NUM_STUDENTS];
getInfo(student);
calcAvg(student);
printGrades(student);
/*...*/
|
That fixed it! Thanks.
Topic archived. No new replies allowed.