0
Algorithm to read 2 notes of a student, calculate and print the final average. Right after you write the message "Calculate another student’s average 1.Yes 2.No?" and request a reply. If the answer is 1, the algorithm must be run again, otherwise it must be terminated by printing the number of students approved. To be approved the student has to have an average greater than or equal to seven
Follows my code:
#include<stdio.h>
int main(void)
{
float nota1,nota2,media1,media2,nota3,nota4,mediaf=1;
int resp;
char aluno1[10],aluno2[10];
while(resp==1)
{
printf("Informe o nome do aluno:");
gets(aluno1);
fflush(stdin);
printf("\nDigite a primeira nota do aluno: ");
scanf("%f",¬a1);
printf("\nDigite a segunda nota: ");
scanf("%f",¬a2);
fflush(stdin);
media1 = (nota1 + nota2)/2;
fflush(stdin);
printf("\na media de %ce : %0.0f\n",aluno1, media1);
printf("\nDigite 1 para continuar ou 2 para sair: ");
scanf("%d", &resp);
}
do
{
fflush(stdin);
printf("Informe o nome do aluno:");
gets(aluno2);
fflush(stdin);
printf("\nDigite a primeira nota: ");
scanf("%f",¬a3);
printf("\nDigite a segunda nota: ");
scanf("%f",¬a4);
fflush(stdin);
media2 = (nota3 + nota4)/2;
printf("\nMedia de %s e: %0.0f\n",aluno2,media2);
fflush(stdin);
printf("\nDigite 1 para continuar ou 2 para sair\n");
scanf("%d", &resp);
}
while (resp==1);
return 0;
}
#include<stdio.h>
int main(void)
{
float nota1,nota2,media1,media2,nota3,nota4,mediaf=1;
int resp;
char aluno1[10],aluno2[10];
while(resp==1)
{
printf("Informe o nome do aluno:");
gets(aluno1);
fflush(stdin);
printf("\nDigite a primeira nota do aluno: ");
scanf("%f",¬a1);
printf("\nDigite a segunda nota: ");
scanf("%f",¬a2);
fflush(stdin);
media1 = (nota1 + nota2)/2;
fflush(stdin);
printf("\na media de %ce : %0.0f\n",aluno1, media1);
printf("\nDigite 1 para continuar ou 2 para sair: ");
scanf("%d", &resp);
}
do
{
fflush(stdin);
printf("Informe o nome do aluno:");
gets(aluno2);
fflush(stdin);
printf("\nDigite a primeira nota: ");
scanf("%f",¬a3);
printf("\nDigite a segunda nota: ");
scanf("%f",¬a4);
fflush(stdin);
media2 = (nota3 + nota4)/2;
printf("\nMedia de %s e: %0.0f\n",aluno2,media2);
fflush(stdin);
printf("\nDigite 1 para continuar ou 2 para sair\n");
scanf("%d", &resp);
}
while (resp==1);
return 0;
}
Have you tried adding a counter for each student insertion? example add the quantities of the variables aluno1 and aluno2, of course the best would be to unify these variables. Try working with case instead of .... while, put a case 1 (EXECUTES CODE) break case 2 Exit break. I believe it will work
– Luiz Augusto