I want to sort the student's grades, but I can not do it because when I receive the grades I'm using the index j, I think that's the problem, but I do not know how to solve it.
#include<stdio.h>
#include<stdlib.h>
double ordena(double *a, double *b);
struct notas
{
double notas[3];
char nome[100];
};
int main(void)
{
int i, j;
struct notas aluno[2];
for(i = 0; i < 2; i++)
{
printf("Informe os nomes dos alunos :");
scanf("%s", aluno[i].nome);
system("cls");
for(j = 0; j < 3; j++)
{
printf("Informe as notas do aluno %d:", j + 1);
scanf("%lf", &aluno[i].notas[j]);
system("cls");
}
system("cls");
}
for(i = 0; i < 2; i++)
{
for(j = i + 1; j < 3; j++)
{
ordena(&aluno[i].notas[j], &aluno[j].notas[j]);
}
}
for(i = 0; i < 2; i++)
{
printf("Nome dos alunos %s:", aluno[i].nome);
for(i = 0; i < 3; i++)
{
printf("%.2lf\n", aluno[i].notas[j]);
}
}
system("pause");
return 0;
}
double ordena(double *a, double *b)
{
double o;
if(*a > *b)
{
o = *a;
*a = *b;
*b = o;
}
return 0;
}