if else compiler problem and parallel arrays

i'm not sure if it's because of the way i'm structuring the parallel arrays that's causing the compiler not to run through all the possibilities, but i'm trying to assign grades by using a parallel array.
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
for (a = 0; a < 10; a++)
{
	cout << left << setw(14) << student_name[a] << ": ";

	for (b = 0; b < 5; b++)
	{
			average += student_score[a][b];
	}

	average = average / 5;

	if (average >= 90)
	{
			grades[a] = 'A';
	}


	else if (average < 90 && average >= 80)

	{
			grades[a] = 'B';
	}


	else if (average < 80 && average >= 70)
	{
			grades[a] = 'C';
	} 

	else if (average < 70 && average >= 60)
	{
			grades[a] = 'D';
	}

	else
			grades[a] = 'F';

				average = 0;
}
	for (int p = 0; p < 10; p++)
	{
			cout << student_name << ": " << grades[a] << endl;
	}


i get the correct average and the compiler only checks the first if statement before moving on. i'm not sure what the problem is

How do you know you get the correct average? How do you know only the first if statement is evaluated?
i have a break point on the first if statement, the compiler goes to that, and then returns to calculating the next average. as for the average, i just averaged it using my phone. in another part of my program i have to output the averages, so i just ran it through my calculator and compared answers. they all checked out. i forgot to mention that this is the output as of right now when i run the program

Please select one menu option

1.) Search and display student's scores by name,                        Enter S
2.) Find average score per student,                                     Enter A
3.) Find score average per class,                                       Enter C
4.) Save into a class stats file all student's names and letter grades, Enter F
5.) Print all class data,                                               Enter P
6.) Quit,                                                               Enter Q

    Selection: f




Mary Peterson : Jake Andersen : Susan Cooper  : Mike Smith    : Jim Blair     : Clark Lee     : Kennedy Davis : Kim Bronson   : Sunny Hill    : Sam Benson    : 009FF500: ╠
009FF500: ╠
009FF500: ╠
009FF500: ╠
009FF500: ╠
009FF500: ╠
009FF500: ╠
009FF500: ╠
009FF500: ╠
009FF500: ╠
C

first of all, it doesn't format the way i want it too, and the final line of the output is correct. the last person (Sam Benson) should be receiving a 'C'.
Last edited on
closed account (48T7M4Gy)
Why in line 40 use p as the index variable, while in line 45 we have grades[a] and student_name without an index at all?

As a start to untangling this, you might like to address a simple exercise in printing out a list of students with one student per line.
well that's not too hard

1
2
3
4
for (int i=0; i < 10; i++)
{
cout << student_name[i] << endl;
}


okay i see my error with the formatting, that was my careless mistake. but i'm still struggling with assigning grades via using a one dimensional array
Last edited on
update: never mind i fixed the problem, thanks for your help everyone
Last edited on
Topic archived. No new replies allowed.