首页 > 试题广场 >

编写一个小程序,要求以几英尺几英寸的方式输入其身高,并以磅为

[问答题]
编写一个小程序,要求以几英尺几英寸的方式输入其身高,并以磅为单位输入其体重。(使用3个变量来存储这些信息。)该程序报告其BMI(Body Mass Index,体重指数)。为了计算BMI,该程序以英寸的方式指出用户的身高(1英尺为12英寸),并将以英寸为单位的身高转换为以米为单位的身高(1英寸=0.0254米),然后,将以磅为单位的体重转换为以千克为单位的体重(1千克=2.2磅)。最后,计算相应的BMI——体重(千克)除以身高(米)的平方,用符号常量表示各种转换因子。
#include<iostream>
using namespace std;
const float FoottoInch(12);
const float InchtoMeter(0.0254);
const float PoundtoKilogram(2.2);
int main()
{
 float foot,inch,pound;
 float height,weight,BMI;
 cout<<"Enter the feet of your height:";
 cin>>foot;
 cout<<endl<<"Enter the inches of your height:";
 cin>>inch;
 cout<<endl<<"Enter the pounds of your weight:";
 cin>>pound;
 height=(foot*FoottoInch+inch)*InchtoMeter;
 weight=pound*PoundtoKilogram;
 BMI=weight/(height*height);
 cout<<endl<<"Your Body Mass Index is:"<<BMI;
 return 0;
}

编辑于 2019-01-24 11:57:00 回复(2)