This is a very simple program I made to test some stuff with structs which I'm new with.
If you try to execute the program, you'll notice that the first if
in the void function is ignored (or maybe not satisfied) even when 19 <= BMI <= 25
#include <stdio.h>
#include <string.h>
#include <ctype.h>
typedef struct {
char name[50];
float weigth;
float heigth;
float BMI;
} subjects;
void check_BMI(subjects Candidate)
{
if (Candidate.BMI >= 19 && Candidate.BMI <= 25)
puts("Subject is probably in good shape");
else
puts("Subject might not be in good shape");
}
int main()
{
subjects Candidate;
Candidate.BMI = Candidate.weigth/(Candidate.heigth * Candidate.heigth);
puts("Insert subject's name: ");
fgets(Candidate.name, 50, stdin);
puts("Insert subject's weigth (in kg): ");
scanf("%f", &Candidate.weigth);
puts("Insert subject's heigth (in m): ");
scanf("%f", &Candidate.heigth);
check_BMI(Candidate);
return 0;
}
What could be my mistake?