C++计算BMI值
代码
//体重指数 = 体重(公斤) 除 身高(米)的平方。即 kg/m2 。
#include <iostream>
using namespace std;
int main()
{
double weight,high,high2;
int BMI;
cout<<"请输入体重(KG)和身高(M):"<<endl;
cin>>weight>>high;
high2 = high*high;
BMI = weight / high2;
cout<<"你的BMI值为:"<<BMI<<endl;
if(BMI<18)
{
cout<<"过轻"<<endl;
}
else if(BMI<=25 && BMI>=18)
{
cout<<"正常体重"<<endl;
}
else if(BMI<=30 && BMI>25)
{
cout<<"超重"<<endl;
}
else if(BMI>30&&BMI<=35)
{
cout<<"轻度肥胖"<<endl;
}
else if(BMI>35&&BMI<=40)
{
cout<<"中度肥胖"<<endl;
}
else if (BMI>40)
{
cout<<"重度肥胖"<<endl;
}
return 0;
}
试运行结果: