新人挠头求助!头都要秃了!多重if-else语句总是无法得出正确结果
//以下是我打的代码,一般都是输入weight为80,height为2,得到结果为20,可是最后的判断结果总是Underweight: less than 18.5。//用if{...}if{...}if{...}if{...}也是同样的判断结果。
//曾经尝试删去包含“Underweight: less than 18.5”的那个判断条件,最后直接得到结果20,没有其他判断结果。
//将整型int换成浮点型float也是出现同样的问题
#include <stdio.h>
#include <stdlib.h>
int main()
{
int weight, height, BMI;//定义体重、身高
int a = BMI = weight/(height*height);//定义身体质量指数BMI
printf("Please enter weight(KG): ");
scanf("%d", &weight);//输入体重
printf("Please enter height(M): ");
scanf("%d", &height);//输入身高
printf("a = BMI = weight / (height * height) = %d\n", weight/(height*height));//得到结果
if(a >= 18.5)
{
printf("Normal: between 18.5 and 24.9");
}
else if(a >= 25)
{
printf("Overweight: between 25 and 29.9");
}
else if(a >= 30)
{
printf("Obese: 30 or greater");
}
else
{
printf("Underweight: less than 18.5");
}
system("pause");
return 0;
}