C编程中的BMI计算器......不能运行?

时间:2015-02-19 15:18:08

标签: c error-handling calculator

#include<stdio.h>
int main()
{
    float h,w,x;
    printf("Enter your height and weight");
    scanf("%f %f",&h,&w);
    w/(h*h)==x;
    scanf("%f",&x);
    if(x<=18.5)
    {printf("You are UNDER WEIGHT");
    }
    else if("x==(18.5&&24.9)")
    {printf("You are AVERAGE");
    }
    else if("x>=(25&&29.9)")
    {printf("You are OVER WEIGHT");
    }
    else
    {printf("OBESITY!!!");
    }
    return 0;
}

我是编程的初学者。我想用嵌套的if else语句做一个复杂的程序。但是我无法执行上面的代码。你能帮助我吗 ? 对不起我的noobness 。在此先感谢:)

2 个答案:

答案 0 :(得分:0)

更改

w/(h*h)==x;
scanf("%f",&x);

if(h) //if h is not zero
    x=w/(h*h); //calculate x

这些

else if("x==(18.5&&24.9)")
else if("x>=(25&&29.9)")

else if(x>18.5 && x<=24.9)
else if(x>=25 && x<=29.9)

答案 1 :(得分:0)

以下行将w /(h * h)与x进行比较。

w/(h*h)==x;

如果您尝试将计算结果分配给x,请使用:

x = w/(h*h);

您还需要删除&#34;&#34;从if语句开始,然后一次评估一个例如。

if(x>18.5 && x<=24.9)