3.1
注:1 英尺=12 英寸
#include<iostream>
using namespace std;
int main()
{
const int change = 12;
cout << "请输入身高:___\b\b\b";//\b是退格转义符
float height;
cin >> height;
float height1 = height / change;
cout << "转换后为:" << height1 << "英尺";
system("pause");
return 0;
}
3.2
#include<iostream>
using namespace std;
int main()
{
//inch 英寸 feet 英尺
float height_inch;
float height_feet;
float weight;
cout << "请依次输入身高英寸和英尺:";
cin >> height_feet >> height_inch;
const int inch_feet_change = 12;
const float feet_meter_change = 0.0254;
float height_meter = (height_inch * inch_feet_change + height_feet) * feet_meter_change;
cout << "请输入体重(pound):";
cin >> weight;
const float weight_change = 2.2;
float weight_kilogram = weight / weight_change;
float BMI = weight / height_meter * height_meter;
cout << "该用户身高为:" << height_meter << "米\n"
<< "该用户体重为:" << weight_kilogram << "kg\n"
<< "该用户BMI为:" << BMI << endl;
system("pause");
return 0;
运行结果
3.2 结果