expected primary-expression before ‘]’

I keep trying to run my code through g++ and for some reason I always get the expected primary-expression before']' and I'm not sure how to make it work. Also the error happens on line twenty after all of the end brackets except for the one with a variable already inputted.
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
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

const int STUDENTS = 10;
const int SCORES = 5;
void namesAndGrades(string name[], int id[], int grade[][SCORES], int oGrade[]);

int main(){
  int ids[STUDENTS];
  char o;
  string names[STUDENTS];
  int grades[STUDENTS][SCORES];
  int overGrade[STUDENTS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

  namesAndGrades (names[], ids[], grades[][SCORES], overGrade[]);
}

void namesAndGrades(string name[], int id[], int grade[][SCORES], int oGrade[]){
  char o;
  ifstream inFile;
  inFile.open("data121.txt");
  if ("data121.txt"){
    for(int i=0; i<STUDENTS; i++){
      inFile >> id[i]>>o;
      getline(inFile, name[i], ',');
      cout<<endl << id[i]<<" ";
      cout  << name[i]<< " ";
      for(int x=0; x<SCORES;x++){
        inFile>>grade[i][x]>>o;
        oGrade[i]+=grade[i][x];
        cout<< grade[i][x]<< " ";
        }
      cout<< oGrade[i]<<endl;
      }
    }
}
Last edited on
 
namesAndGrades(names, ids, grades, overGrade);
@Peter87 thanks for the help changed it and program ran perfectly thanks again
This part

1
2
3
4
  char o;
  ifstream inFile;
  inFile.open("data121.txt");
  if ("data121.txt"){

should be

1
2
3
  // you don't use the variable o
  ifstream inFile("data121.txt");   // you can open the file like this
  if (inFile){    // need to check inFile here 

Topic archived. No new replies allowed.