请大侠帮我编个程序

来源:百度知道 编辑:UC知道 时间:2024/04/29 11:18:30
体重指数BMI的计算
BMI=体重*703/身高的平方
(其中体重以磅为单位,1磅=0.4536KG,身高以英寸为单位,1英寸=2.54厘米)
BMI 体重指数解释
<20 过瘦
20-25 正常
26-30 超重
>30 肥胖症
要求用户输入身高和体重,然后计算BMI,通过屏幕输出结果以及建议

#include <stdio.h>
main()
{
float weight,height;
float bmi;
printf("please intput weight and height:\n");
scanf("%f%f",&weight,&height);
//这里没有涉及单位转换的过程,如果需要,把下面两句加上。
//weight=0.4536*&weight;
//height=hright/2.54;
bmi=weight*703/height^2;
if (bmi<=20 )
printf("too low\n");
if (bmi>20&&bmi<=25)
printf("normal\n");
if(bmi>26&&bmi<=30)
printf("fat\t");
if(bmi>30)
printf("too fat]n");
}

#include <iostream>

using namespace std;

int main()
{
double weight,height;
double BMI;

cout<<"输入体重(以磅为单位):";
cin>>weight;
cout<<"输入身高(以英寸为单位):";
cin>>height;

BMI = weight*703 / (height*height); //这里不加括号的话,运算顺序错误,而且平方是height*height,不是height*2,而且这个算法是以磅跟英寸计算的,所以得先计算