primer three_Practice

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值