Reverse 2d array (HELP!)

Hello again guys, i have this following assignment:

Marks obtained by all students are stored in a two-dimensional array. Each row records a student’s marks for five tests. For example, the following array stores the test marks for eight students.


{12,14,13,14,15},
{17,13,14,13,13},
{13,13,14,13,13},
{19,13,14,17,13},
{13,15,14,13,16},
{13,14,14,16,13},
{13,17,14,18,13},
{16,13,15,19,12}};




Write a program that displays students and the total marks they obtained in five tests, in decreasing order of the total marks.


This is my CODE:

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

#include <iostream>
using namespace std;

int main(){
	
	int sum = 0;
	int array [8][5]={
		
	{12,14,13,14,15},
	{17,13,14,13,13},
	{13,13,14,13,13},
	{19,13,14,17,13},
	{13,15,14,13,16},
	{13,14,14,16,13},
	{13,17,14,18,13},
	{16,13,15,19,12}};
	
	for (int row=0;row<8;row++){
		for (int column=0;column<5;column++){
			cout<< array [row][column] <<" ";
		}
		cout << endl;
	}
	
	
// finding the row sum 
    for (int i = 0; i < 8; ++i) { 
        for (int j = 0; j < 5; ++j) { 
  
            // Add the element 
            sum = sum + array[i][j]; 
        } 
  
        // Print the row sum 
        cout 
            << "Sum of the row "
            << i << " = " << sum 
            << endl; 
  
        // Reset the sum 
        sum = 0; 
        
  for (int a=8;a>=0;a--) {
    for (int b=5;b>=0;b--) { 
    
            sum = sum + array[a][b]; 
		}

        cout 
            << "Sum of the row "
            << i << " = " << sum 
            << endl; 
  
        // Reset the sum 
        sum = 0;
		
		
  }  
        
    }

}
/////////////////////////////  


From line 44 to line 62 im having issues, since all the large grades are being outputted from the smallest to the largest, i just decided to reverse all of that so all the large grades will be outputted first. I would really appreciate some help.
Last edited on
I'd start with
int sum[8] = { 0 };

Then you can have a score for each student.

You can then sort this into your rank order, and as you sort sum, you can sort array in step with it.
My first language is spanish, and i dont really understand what youre saying
Dice que necessitas una lista de las sumas de todos los grados para cade estudiante.

Después, puedes ordenar los estudiantes usando la lista de sumas. Yo usaría algo como un selection sort: búsqa la suma más grande, imprime el estudiante corrispondiente. Haz zero (o negativa) la suma para el estudiante, y repetir, hasta imprimir todos los estudiantes.


He says that you need a list of the sum of each student’s grades.

After that, you can sort the students using the list of sums. I would use something like a selection sort: find the largest sum, print the corresponding student. Zero (or make negative) the sum for that student, and repeat, until you have printed all the students.


Hope this helps.
Registered users can post here. Sign in or register to post.