-1
Hello! How are you? I’m having a problem when I run my program, it’s a program to calculate four medias and divide by four, and it’s necessary to do this using If and Else, but when I run it, the program reads the first condition, and if the if for Else input the program reads normally, however when the "Student" is approved the program executes the printf of Approved then executes the printf of FAILED, and if it was approved, it was not to execute the failed. Can someone help me?
#include <stdio.h>
#include <conio.h>
int main () {
//VARIAVEIS
float media, nota1, nota2, nota3, nota4, recMedia, receberec;
printf("\n VAMOS CALCULAR SUA NOTA\n");
printf("\nPRESSIONE ENTER...\n");
getch();
//ENTRADA DE DADOS
printf("\n---------------------------\n");
printf("\nDIGITE SUA PRIMEIRA NOTA\n");
scanf("%f", ¬a1);
printf("\nDIGITE SUA SEGUNDA NOTA\n");
scanf("%f", ¬a2);
printf("\nDIGITE SUA TERCEIRA NOTA\n");
scanf("%f", ¬a3);
printf("\nDIGITE SUA QUARTA NOTA\n");
scanf("%f", ¬a4);
printf("\n---------------------------\n");
printf("\nPRESSIONE ENTER PARA CALCULAR\n");
getch();
//ENTRADA DE PROCESSAMENTO
printf("\nPRONTO JA VALIDAMOS SUA MEDIA!\nQUE RUFEM OS TAMBORES...\n");
media = (nota1+nota2+nota3+nota4)/4;
printf("\nSUA MEDIA:\t%.2f", media);
printf("\n---------------------------\n");
if (media>=7) {
printf("\n\tAPROVADO!\n%.2f", media);
}
else {
printf("\n\tREPROVADO!\n");
printf("\nINSIRA SUA NOTA DE EXAME:");
scanf("%f",&recMedia);
printf("\nMEDIA DE EXAME:\t\n%.2f", recMedia);
}
receberec = (recMedia+media)/2;
if (receberec>=7) {
printf("\n\tAPROVADO EXAME!\n%.2f", receberec);
}
else {
printf ("\n\tREPROVADO EXAME!\n%.2f", receberec);
}
printf("\n---------------------------\n");
getch();
printf("\nFIM\n");
system ("PAUSE");
return (0);
}
For example if the student gets 10 media, the program shows that he has passed, but also performs the part of failed exam.
– Matheus S. Gomes
Matheus, you can edit the question and describe the problem, read the [tour] to know how the site works, if you need help on how to use the tool, visit the [help].
– NoobSaibot
Oppa! Yes, thank you very much for your attention... I’ve already edited!
– Matheus S. Gomes
The problem is that you show the exam result anyway, so automatically if the person is approved, they fail the exam (as it will be considered the "zero" of the exam). You need to condition your test to fail only.
– Bacco
Thank you very much! I got the problem solved, that was exactly it!
– Matheus S. Gomes
If the problem has been solved, upvote the Bacco comment.
– Ronaldo Araújo Alves