该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
求助
我在自学c语言,刚学,有很多地方不懂,例如这个计算BMI的东西,为什么第一个输出的结果只有超重,第二个可以正常输出,求各位大神大佬指导~
第一个
#include
int main(void)
{
float height;
float weight;
printf("Please enter your height, note, in meters!");
getchar();
scanf("%f", &height);
printf("Please enter your weight, note, in kilograms!");
getchar();
scanf("%f", &weight);
if(weight / (height * height) >= 28)
{
printf("You are already obese, please pay attention to control diet, work and rest habits!\n");
}
else if(weight / (height * height) < 28, weight / (height * height) >= 24)
{
printf("Your weight is not obese, but already overweight, please pay attention to your daily eating habits!\n");
}
else if(weight / (height * height) < 24, weight / (height * height) >= 18.5)
{
printf("Congratulations, your body mass index is normal, please continue to maintain good habits of work and rest!\n");
}
else if(weight / (height * height) < 18.5)
{
printf("You are a little thin, this is also unhealthy, please strengthen exercise, pay attention to eating habits.\n");
}
return 0;
}
第二个
#include
int main(void)
{
float height;
float weight;
printf("Please enter your height, note, in meters!");
getchar();
scanf("%f", &height);
printf("Please enter your weight, note, in kilograms!");
getchar();
scanf("%f", &weight);
if(weight / (height * height) > 0)
{
if(weight / (height * height) >= 28)
{
printf("You are already obese, please pay attention to control diet, work and rest habits!\n");
}
else if(weight / (height * height) < 28, weight / (height * height) >= 24)
{
printf("Your weight is not obese, but already overweight, please pay attention to your daily eating habits!\n");
}
else if(weight / (height * height) < 24, weight / (height * height) >= 18.5)
{
printf("Congratulations, your body mass index is normal, please continue to maintain good habits of work and rest!\n");
}
else if(weight / (height * height) < 18.5)
{
printf("You are a little thin, this is also unhealthy, please strengthen exercise, pay attention to eating habits.\n");
}
}
}