Invalid type

On line 90, I am getting this error, "[Error] invalid types 'int[int]' for array subscript." Please help (Prompt is out << tGrade[i]<< "%" < lGrade[i];)
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
92

#include <fstream>

using namespace std;

char answer[20];
char student[20];
char id[8];
int tGrade[150];
char lGrade [150];

void aEntry(char answer[]);
void sEntry (char id[], char student[]);
void sEval (char student[], char answer[]);
void print (char id[], char student[], int tGrade[], char grade[]);

int main()
{
 	aEntry (answer);
	sEntry (id, student);
	sEval (student, answer);
	print(id, student, tGrade, lGrade);
}

void aEntry(char answer[])
{
	ifstream in;
	ofstream out;
	
	int i; 
	for (i=1; i < 21; i++) //May be modified
	{	
		in >> answer[i];
		out << endl;
	}
}
void sEntry (string id, char student[])
{	
	 ifstream in;
	 ofstream out;
  
  	 int i;
	 for (i=0; i < 150; i++)
	 {	 
	 	 in >> id;
		 in.ignore (1,'A');
		 in >> student; 
	 } 
}
void sEval(char student[], char answer[])
{
	int points;
	int i;
	for (i=0; i < 150; i++)
	{
		for (i=0; i <20; i++)
		{	
			if (answer[i] == student[i])
			   points += 2;
	 		else if (answer[i] != student[i])
			   points -= 1;
			else if (student[i] == ' ')
			   continue;	     
		}
		tGrade[i] = points / 40;
	}
	for (i=0; i < 150; i++)
	{
		if (tGrade[i] <= 100 && tGrade[i] >= 90)
		   lGrade[i] == 'A';
 		if (tGrade[i] <= 89.99 && tGrade[i] >= 80)
		   lGrade[i] == 'B';
  		if (tGrade[i] <= 79.99 && tGrade[i] >= 70)
		   lGrade[i] == 'C';
  		if (tGrade[i] <= 69.99 && tGrade[i] >= 60)
		   lGrade[i] == 'D';
  		if (tGrade[i] <= 59.99 )
		   lGrade[i] == 'F';
	}
}
void print (string id, char student[], int tGrade, char grade)
{
	ifstream in;
	ofstream out;
	
	int i;
	for (int i=0; i < 150; i++)
	{	
		out << id[i] << " "<< student[i]<< " ";
		out << tGrade[i]<< "%" < lGrade[i];
	}
}
Last edited on
out << tGrade[i]<< "%" << lGrade[i];

You're missing a <
Last edited on
The same problem is occuring
Oh.

1
2
int tGrade[150];
void print (string id, char student[], int tGrade, char grade)


Why are you using the same name twice in the same scope? At line 90, tGrade[i] is referring to the local tGrade variable. Not the global tGrade array. Change the name in one of the two places, probably the method parameter would be easier.

You really shouldn't be using global variables at all.
Your function prototypes and functions are inconsistent in the use of char arrays and strings.

Line 3: You haven't included the <string> header.

Lines 6-10: Globals are evil.

Line 13: sEntry is declared to take a char array.
Line 37: sEntry takes a string.

Line 15,81: Ditto.

Line 89: You're trying to output the i'th character of the id and student. Is this really what you want?

Line 81,90: tGrade is passed as a simple int, but you're trying to reference it as an array.


Topic archived. No new replies allowed.