第十七周项目三 胖子伤不起

项目要求:

根据世界卫生组织推荐的体重标准,男性的标准体重=(身高cm-80)×70﹪,女性的标准体重 =(身高cm-70)×60﹪。标准体重正负10﹪为正常体重;标准体重正负10﹪~20﹪为体重过重或过 轻;标准体重正负20﹪以上为肥胖或体重不足,其中超重计算公式为:超重(%)=[(实际体重-标准 体重)/(标准体重)]×100%,体重的单位是kg。

请编程序,输入一个人的姓名、性别、身高、体重,用一句人性味浓的话语输出其体重情况(正 常、过重、过轻、肥胖或体重不足),这个程序可以用于体重计上为人们实时报告体重情况。

要求使用结构体类型表示人的相关信息。

 

问题及代码:

#include <iostream>
using namespace std;
struct Person
{
    string name;
    int sex;
    double height;
    double weight;
} person;
int main()
{
    double standard_weight;
    cout<<"Enter Name:"<<endl;
    cin>>person.name;
    cout<<"\nEnter sex(male=1;female=2):"<<endl;
    cin>>person.sex;
    cout<<"\nEnter height(cm):"<<endl;
    cin>>person.height;
    cout<<"\nEnter weight(kg):"<<endl;
    cin>>person.weight;
    if (person.sex==1)
        standard_weight=(person.height-80.0)*0.7;
    else
        standard_weight=(person.height-70.0)*0.6;
    cout<<"\n\nLet me see......\n\n";
    if (person.weight>standard_weight*1.2)
        cout<<"Oh, you're too fat,overweight "<<((person.weight-standard_weight)/standard_weight)<<"%"<<endl;
    else if (person.weight<standard_weight*0.8)
        cout<<"Oh, you're too thin,underweight ";
    else
        cout<<"Oh, Your figure is perfect!"<<endl;
    return 0;
}


运行结果:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值