'What code I must input to display the ranks, student numbers and their average using array?

I want to show the ranks, student numbers and average but idk how. Here's my code:

/* CODES */
#include<iostream>
using namespace std;

int main() {
    int grades[100];
    float sum, ave, add, score1, score2, score3, score4;
    
    cout << "How many students do you want to input? ";
    cin >> grades[100];
        
    for (int i=0; i<grades[100]; i++){
        cout << "\nInput Average Grade of Student #" << i+1 << endl;

        for (int j=0; j<1; j++){
        cout << "First Grading Period: ";
        cin >> score1;
        
        for (int attempt1=0; attempt1>=0; attempt1++){
            if (score1 < 65 || score1 > 100){
               cout << "INVALID INPUT. Input again: ";
               cin >> score1;
            }
            else{
                break;
            }
        }
    }

        for (int j=0; j<1; j++){
        cout << "Second Grading Period: ";
        cin >> score2;
        
        for (int attempt2=0; attempt2>=0; attempt2++){
                if (score2 < 65 || score2 > 100){
                cout << "INVALID INPUT. Input again: ";
                cin >> score2;
                }
                else{
                break;
                }
            }
        }

        for (int j=0; j<1; j++){
        cout << "Third Grading Period: ";
        cin >> score3;

        for (int attempt3=0; attempt3>=0; attempt3++){
        if (score3 < 65 || score3 > 100){
                cout << "INVALID INPUT. Input again: ";
                cin >> score3;
                }
                else{
                break;
                }
            }
        }

        for (int j=0; j<1; j++){
        cout << "Fourth Grading Period: ";
        cin >> score4;

        for (int attempt4=0; attempt4>=0; attempt4++){
        if (score4 < 65 || score4 > 100){
                cout << "INVALID INPUT. Input again: ";
                cin >> score4;
                }
                else{
                break;
                }
            }
        }
        
    
        sum = score1+score2+score3+score4;
        ave = sum/4;
           
        cout << "=============================" << endl;
        cout << "Average of Student #" << i+1 << ": " << ave << endl;  
    }
    
    
    
    return 0;
}

The output of the code above, it shows the grades and average of every students that I inputted:

How many students do you want to input? 3

Input Average Grade of Student #1
First Grading Period: 85
Second Grading Period: 85
Third Grading Period: 85
Fourth Grading Period: 85
=============================
Average of Student #1: 85

Input Average Grade of Student #2
First Grading Period: 100
Second Grading Period: 100
Third Grading Period: 100
Fourth Grading Period: 100
=============================
Average of Student #2: 100

Input Average Grade of Student #3
First Grading Period: 90
Second Grading Period: 90
Third Grading Period: 90
Fourth Grading Period: 90
=============================
Average of Student #3: 90

Now the problem is how I will display the ranks, student numbers and average. This is the sample output for the ranks, student numbers, and average that I want to display:

RANKS STUDENT NO. AVERAGE
1     2           100
2     3           90
3     1           85
c++


Solution 1:[1]

When you want to store the information of student average grade, you should use 2 dimensional std::vector, where the first array could be student number (or even student name) and the second array would be the student grades.

Then you need to figure out how to use the std::sort() function to sort the students by their average grade and print it out to the screen with the corresponding rank e.g. 1, 2, 3, ...

The output after sorting would look like this:

[rank]    [student_number_from_matrix]    [corresponding_student_avg_grade]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lost Control