One:
#include <iostream>
using namespace std;
int main()
{
int height_in,height_fo;//定义两个标识符分别存放英寸和英尺的身高
const int IN_TO_FOOT=12;//定义一个英尺与英寸间转换因子
cout << "Please enter your height in inches:";
cin >> height_in;//输入身高
height_fo=height_in/IN_TO_FOOT;//把英寸转换为英尺
cout <<"Your height is "<< height_in <<" inches and " << height_fo << " foots." << endl;//分别以英尺和英寸输出身高
return 0;
}
Two:
#include <iostream>
using namespace std;
int main()
{
int height_in,height_fo;//定义标识符分别存放英寸和英尺的身高
int height_meter;//存放以米为单位的身高值
float bmi,weight;//存放体重和BMI指数(Body Mass Index)
const int IN_TO_FOOT = 12;//定义一个英尺与英寸间转换因子
const float IN_TO_ME = 0.0254;//英寸到米的转换因子
const float PN_TO_KG = 2.2;//磅到千克的转换因子
cout << "Please enter your height in inches section: ";
cin >> height_in ;//输入身高中的英寸部分
cout << endl;
cout << "Please enter your height in foots section: ";
cin >> height_fo;//输入身高中的英尺部分
cout << endl;
height_meter =( height_fo * IN_TO_FOOT + height_in ) * IN_TO_ME;
cout << "Please enter your weight in pound: ";
cin >> weight;//输入体重
cout << endl;
weight = weight / PN_TO_KG;//将体重转换为千克
bmi = weight/(height_meter^2);//求BMI指数
cout << "Your Body Mass Index is " << bmi << endl;
return 0;
}