statement:
A student's grade is calculated from three grades assigned between the range of 0 to 10, respectively, to a work of bi-monthly assessment and final examination. The average three notes mentioned above obeys the pessos: work of laboratory: 2; semester evaluation: 3; final exam: 5. According to the result, show on the screen whether the student is in default (mean between 0 and 2.9), recovery (between 3 and 4.9) or if it was approved. Make all the necessary checks.
Good. I had done with a float function, which returned the variable. For learning purposes, I decided to try to do pointer, but did not work very well kkk
In the part of the function that will validate the note
while (var 10)
If I type 5 for example, it is 0 and 1. But I do not quite understand why .. then 0 or 1 of 1, then it enters and stays in a loop, asking to enter a valid note. Why does this happen? Thank you in advance.
follow 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");
}