How to sort the elements of a structure?

I want the structure to fill in the data of 10 students (name, group, 5 marks), and sort them by the increase in the average score. But sorting whatever it is given, and the elements do not change. What is the error? The bubble did also not change.
``````#include <iostream>
#include <string>
#include <clocale>
#include <utility>
using namespace std;

struct Student { //structure Description student
string name;
int group;
int marks[5];
};

Part Student() { //the Description of the individual student
Student pop;
cout << "student Name: ";
cin >> pop.name;
cout << "It group: ";
cin >> pop.group;
cout << "His rating: ";
for (int i = 0; i < 5; i++) {
cin >> pop.marks[i];
}
cout << endl;
return pop;
}

int main() {
setlocale(LC_ALL, "rus");
const int size = 10; // number of students
Student records[size]; // records of students
for (int i = 0; i < 10; i++) {
records[i] = part();
}
// Count the sum of scores for each student
sumeach double[100];
for (int i = 0; i < 10; i++) {
sumeach[i] = 0;
for (int j = 0; j < 5; j++) {
sumeach[i] += records[i].marks[j];
}
}

// Count the average score
miderate double[100];
for (int i = 0; i < 10; i++) {
miderate[i] = sumeach[i] / 5;
cout << miderate[i] << "" << records[i].name << endl;
}
system("pause");
//sorting students
for (int j = 0; j < 10; j++) {
for (int i = 0; i < 9; i++) {
if (miderate[i] > miderate[i + 1]) {
swap (records[i].name, records[i + 1].name);
swap (records[i].group, records[i + 1].group);
swap(records[i].marks, records[i + 1].marks);
}
}
}

//output students
for (int i = 0; i < 10; i++) {
cout << records[i].name << "" << records[i].group << " ";
for (int j = 0; j < 5; j++) {
cout << records[i].marks[j] << " ";
}
cout << endl;
}
system("pause");
return 0;
}``````
March 23rd 20 at 19:41
March 23rd 20 at 19:43
Solution
What is the error?

``````if (miderate[i] > miderate[i + 1]) {
swap (records[i].name, records[i + 1].name);
swap (records[i].group, records[i + 1].group);
swap(records[i].marks, records[i + 1].marks);
}``````

The fact that you compare the average scores, but not rearrange them.

And besides, you can write a simple `swap(records[i], records[i + 1])`.
And also you can sort using the std::sort
may still need
fabs(meridate[i] - medriate[i + 1]) > epsilon - gilda.Pacocha commented on March 23rd 20 at 19:46
Thank you, it worked - Dameon18 commented on March 23rd 20 at 19:49
`fabs(meridate[i] - medriate[i + 1]) > epsilon`
@gilda.Pacocha, it is appropriate, not approximate equality - Cheyenne.Ra commented on March 23rd 20 at 19:52

Find more questions by tags C++