Difficulty with If / Else

-1

Hello! It's OK? I'm having a problem when I run my program, it's a program to calculate four means and divide by four, and it's necessary to do this using If and Else, but when I execute, the program reads the first condition, and if the input of if Else the program reads normally, but when the "Student" is approved the program executes the printf of APPROVED and then executes the Printf of REPROVADO, being that if it was approved, it was not to execute the reprobate. 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", &nota1);
printf("\nDIGITE SUA SEGUNDA NOTA\n");
scanf("%f", &nota2);
printf("\nDIGITE SUA TERCEIRA NOTA\n");
scanf("%f", &nota3);
printf("\nDIGITE SUA QUARTA NOTA\n");
scanf("%f", &nota4);

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);
}
    
asked by anonymous 15.09.2018 / 23:48

1 answer

0

You are not giving an initial value to recMedia . When it has the result "APPROVED" in the first 'if', there is no way to know what the value of recMedia is.

Give an initial value to all variables.

    
16.09.2018 / 19:40