1
Good night, my friends!
I’m starting the ADS course and I have a question. I need to create a loop of repetition for 50 students by collecting 4 grades of 4 exams, and at the end, present a report with the grades of each of the individuals and the overall average of the class. Well, I already pulled the job (for those who are thinking I want to cheat the teacher and by table fool me along rs. I managed to make the average, however, I could not declare the individual notes :(... In my logic, to do this, I would have to create a var for each of the students and keep the results there, but that would be an unnecessary job and I couldn’t think of another way. Does anyone have any idea how to do it? I use the book Damas' Language C and I couldn’t find anything like it either.
My code only with general media:
#include <stdio.h>
main()
{
char q1,q2,q3,q4;
int alunos,totalunos,notaturma,notaq1,notaq2,notaq3,notaq4;
float media;
for (alunos=1;alunos<=2;alunos++)
{
printf("\nSua resposta da questao 1: "); scanf(" %c",&q1);
printf("\nSua resposta da questao 2: "); scanf(" %c",&q2);
printf("\nSua resposta da questao 3: "); scanf(" %c",&q3);
printf("\nSua resposta da questao 4: "); scanf(" %c",&q4);
if (q1=='A')
notaq1=notaq1+2;
if(q2=='C')
notaq2=notaq2+2;
if(q3=='A')
notaq3=notaq3+2;
if(q4=='C')
notaq4=notaq4=2;
totalunos++; //Coletará o total de alunos para ser usado no calculo da média de notas//
}
notaturma=notaq1+notaq2+notaq3+notaq4;
totalunos=totalunos-1; //Retirei um pois estava sendo contato um aluno a mais//
media=notaturma/totalunos;
printf("\n%2.f E A MEDIA DA TURMA",media);
}
Note that defining individual variables for each grade of each of the 50 students is unproductive and impractical, so we use an array. For this case we can declare
char nota[50][4];
where each row of this array represents a student and each column the concept of a proof. What you haven’t explained is what are the possible concepts and how you turn the concept into a note for calculating the average. Maybefloat nota[50]4];
is more suitable for the calculation of the average and each note could easily be transformed into a concept considering ranges of values.– anonimo
Perfect! The teacher had not given this concept, but charged kkkkkkkkkkkkkkkkkkk Thank you very much, I will research on array.
– Eduardo Lelis