I'm writing a program where the user inputs four test grades each for three students, the values of which are stored in the array grades[3][4]. These grades are then averaged together (again, in a 2D array) and the letter grade is also calculated and displayed in an array.
I then try to output all of the different values in another array so that they are displayed as one big table, like below.
Student Test 1 Test 2 Test 3 Test 4 Avg Grade
Student 1 90 90 100 100 95 A
Student 2 94 90 91 89 91 B
Student 3 64 67 66 63 65 F
Instead, this shows up:
Student Grade 1 Grade 2 Grade 3 Grade 4 Avg Grade
Student 3 D D D D D A
Student 3 [ [ [ [ [ A
Student 3 B B B B B A
*this is a diamond
^this is the symbol for female
I've narrowed it down to this function causing the issue.
Could be a segmentation fault: that is when you try to access memory you shouldn't.
You get into this situation with bad pointers, or when you go out of bounds using an array.
Examples:
1 2 3 4 5
int *p = newint[10];
p[25] = 1; // out of bounds: possible segmentation fault
delete[] p;
p[0] = 1; // "dangling" pointer: possible segmentation fault
In your own code parameter average is shown as double average[][1], but you access:
output[1][5] = average[0][0];
output[1][5] = average[1][1]; // !!!
output[1][5] = average[2][2]; // !!!
output[2][5] = average[0][3]; // !!! you don't reset r
output[2][5] = average[1][4]; // !!!
output[2][5] = average[2][5]; // !!!
// and so on
In fact I may be wrong, because if(i=0){ resets i to zero every time.
This is because it's an assignment =, not a comparison ==.
I realized that I had been resetting i to zero a few minutes after posting this. I've edited the original post to reflect that change, as it still isn't working properly.
I need to find a way to make sure the letter grades are actually letters and to make the output for each grade value actually be what was inputted into the original array.