您的位置:首页 > 编程语言 > C语言/C++

C++ Primer Plus 6书后习题 第3章

2018-02-19 20:42 253 查看




3-1#include<iostream>
using namespace std;

const int inch_per_feet = 12;

int main()
{
cout << "pleaase enter your height in inches:___\b\b\b";
int ht_inch;
cin >> ht_inch;
int ht_feet = ht_inch / inch_per_feet;
int rm_inch = ht_inch%inch_per_feet;
cout << "your height is " << ht_feet << "feet,and"
<< rm_inch << "inches\n";
return 0;
}
3-2#include <iostream>
using namespace std;
int main()
{
cout << "请输入您的身高(以英尺 英寸”的方式输入):";
int h_ft = 0;//输入英尺
int h_in = 0;//输入英寸
cin >> h_ft >> h_in;
cout << "请输入您的体重(单位:磅):";
int w = 0;//输入磅
cin >> w;
const int FT_TO_IN = 12;//转换因子
const double IN_TO_M = 0.0254;
const double P_TO_KG = 1 / 2.2;
cout << "您的BMI是:" << (w * P_TO_KG) / (((h_ft * FT_TO_IN) + h_in) * IN_TO_M) << endl;
return 0; 3-3
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: