您的位置:首页 > 其它

项目2--胖子伤不起

2014-02-27 17:03 351 查看
/*
*程序的版权和版本声明部分:
*Copyright(c)2013,烟台大学计算机学院学生
*All rights reserved.
*文件名称:
*作者:尚振伟
*完成日期:2014年2月27日
*版本号:v0.1
*对任务及求解方法的描述部分:
*输入描述:无
*问题描述:根据世界卫生组织推荐的体重标准,计算一个人的体重情况。
*程序输入:
*程序输出:
*问题分析:
*算法设计:
*我的程序:
*/
#include <iostream>
using namespace std;
struct People
{
char name[20];
char sex;
double height;
double weight;
} peo;
int main()
{
double bweight,overweight;   //分别代表标准体重和超重百分比
cout<<"请输入姓名  性别  身高  体重"<<endl;
cin>>peo.name>>peo.sex>>peo.height>>peo.weight;
if(peo.sex=='F')    //F和M分别代表女性和男性
{
bweight=(peo.height-70)*0.6;   //女性的标准体重
}
else
{
bweight=(peo.height-80)*0.7;   //男性的标准体重
}
overweight=(peo.weight-bweight)/bweight;
if(overweight<0.1&&overweight>-0.1)
{
cout<<"正常"<<endl;
}
else
{
if(overweight>=0.1&&overweight<0.2)
{
cout<<"过重"<<endl;
}
else
{
if(overweight<=-0.1&&overweight>-0.2)
{
cout<<"过轻"<<endl;
}
else
{
if(overweight>=0.2)
{
cout<<"肥胖"<<endl;
}
else
{
cout<<"体重不足"<<endl;
}
}
}
}
return 0;
}

结果展示:



心得体会:用char类型定义变量sex,不能输入汉字,只好用F和M分别代表女性和男性。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: