Hello, I have a task to make a structure, then sort it, etc. 
On the last two points do not pay attention, have not yet done.
I kind of found a way to make a structure, but I can't normally bring it out.
#include <iostream> #include <string> using namespace std; #define N 3 struct STUDENT { char name[30]; int group; int ses[5]; }; int sum, sra; int *p = &sra; int cmp( const void *p1, const void *p2 ) { return ( *( int * )p1 - * ( int * )p2 ); } int main() { STUDENT stud1[N]; for( int st = 0; st < N; st++ ) { cout << "Input first name: "; cin.getline( stud1[st].name, 30 ); cout << "Input number of group: "; cin >> stud1[st].group; for( int i = 0; i < 5; i++ ) { cout << "Input mark " << i + 1 << ": "; cin >> stud1[st].ses[i]; } for( int i = 0; i < 4; i++ ) { sum = sra = 0; sum = stud1[st].ses[i] + stud1[st].ses[i + 1]; sra = sum / 5; } cout << endl; cin.get(); } qsort( p, N, sizeof( STUDENT ), cmp ); int fl = 1; for( int i = 0; i < N; i++ ) { int j = 0; while( ( j < 5 ) && ( stud1[i].ses[j] != 2 ) ) { j++; } if( j < 5 ) { fl = 0; cout << "Student " << stud1[i].name << " (group " << stud1[i].group << ") have mark 2" << endl; } } if( fl ) { cout << "No students, which have mark 2" << endl; } system( "pause" ); return 0; } I tried to derive this:
for( int st = 0; st < N; st++ ) { cout << stud1[st].name << " " << stud1[st].group << " " << stud1[st].ses[i] << endl; } and so
for( int st = 0; st < N; st++ ) { for( int i = 0; i < 5; i++ ) { cout << stud1[st].name << " " << stud1[st].group << " " << stud1[st].ses[i] << endl; } } But in the first case, the last pillar does not display at all, and in the second each record is repeated 5 times (the number of assessments)
Help please find a solution)
And I just found out that sorting for some reason does not work, do not tell me what is my mistake?