0
I’m studying C and I want to make an algorithm that reads the names of 30 students in a class and returns the highest grade, lowest grade and the names of these students. I have already researched a lot and still can’t put the name of the students with the highest and lowest grade. My code so far is like this (with error):
#include<stdio.h>
main(){
char aluno[21],Maluno[21], maluno[21];
float nota, maiorNota=0, menorNota=10;
int i;
for(i=0; i<30; i++){
printf("Insira o nome do(a) aluno(a) %d:\n", i+1);
fflush(stdin);
scanf("%s", aluno);
printf("Insira a nota do(a) aluno(a) %s:\n", aluno);
fflush(stdin);
scanf("%f", & nota);
if(nota>=0 && nota <=10){
if(maiorNota<nota){
maiorNota = nota;
Maluno = aluno;
}
if(menorNota>nota){
menorNota = nota;
maluno = aluno;
}
}
}
printf("Aluno com a menor nota e o: %s\n que tirou%f\n" ,maluno,menorNota );
printf("Aluno com a maior nota e o: %s\n que tirou%f\n" ,Maluno,maiorNota );
}
Someone would know how to do that?
I used this string library function but it keeps going wrong. I have no idea what I’m doing wrong
– Jackgba
if(highest case<note){ highest case = note; strcpy(highest case,student); } if(lowest case>note){ bottom strcpy(menoraluno,);
– Jackgba
@Jackgba adjusted the answer, had forgotten the part of the delimiter character
– Shinforinpola
The
scanf()
already puts the'\0'
in the string. It is not necessary to do so before, but it is convenient to limit the scanf to avoid buffer overflow:scanf("%20s", aluno);
– pmg