4
Enunciation:
A student’s grade is calculated from three grades awarded from 0 to 10 respectively to laboratory, a bimonthly evaluation and a final examination. The average three notes mentioned above follows the steps: work of laboratory: 2; semi-annual evaluation: 3; final examination: 5. According to the result, show on the screen if the student is flunked (average between 0 and 2,9), recovery (between 3 and 4,9) or if it was approved. Knife all necessary checks.
I had done it with a float function, which returned the variable. For reasons of learning I decided to try to do with pointer, but it didn’t work very well.
In the part of the function that will validate the note
while (var < 0 || var > 10)
If I type 5 for example, he gives 0 and 1, but I don’t quite understand why then 0 or 1 of 1, then he enters and stays in a loop asking to type a valid note. Why does this happen?
Follows the code:
#include <stdio.h>
#include <locale.h>
void validar(float *var){
scanf("%f", var);
while (var < 0 || var > 10){
printf("\nNota invalida, tente novamente: ");
scanf("%f", var);
}
}
int main(){
setlocale(LC_ALL, "portuguese");
float lab, avaliacao, exame;
printf("Entre com a nota do trabalho de laboratorio: ");
validar(&lab);
printf("Entre com a nota da avaliação bimestral: ");
validar(&avaliacao);
printf("Entre com a nota do exame final: ");
validar(&exame);
float media = (lab * 2 + avaliacao * 3 + exame * 5) / (2+3+5);
printf((media < 3) ? "\nAluno reprovado.\n" : (media < 5) ? "\nAluno em recuperação\n" : "\nAluno aprovado\n");
}