您的位置:首页 > 其它

17周课后自主-项目三-胖子伤不起

2014-12-22 10:26 302 查看
//show the status of your weight
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
enum status{thin_much,thin,normal,fat,fat_much};//枚举五种状态
struct person  //定义结构体
{
string name;
string sex;
double height;
double weight;
};
void printinfo(person*);
int main()
{
person ap;
cin>>ap.name>>ap.sex>>ap.height>>ap.weight;
printinfo(&ap);
return 0;
}
//打印信息
void printinfo(person* p)
{
string r;
status s;
double std_weight;
if(p->sex == "man")
{
std_weight = (p->height - 80) * 0.7;
}else if(p->sex == "woman")
{
std_weight = (p->height - 70) * 0.6;
}
double t = abs(p->weight - std_weight)/std_weight;
if(p->weight > std_weight)
{
if(t <= 0.1)
{
s = normal;
}else if(t > 0.1 && t <= 0.2)
{
s = fat;
}else if(t > 0.2)
{
s = fat_much;
}
}else if(p->weight < std_weight)
{
if(t <= 0.1)
{
s = normal;
}else if(t > 0.1 && t <= 0.2)
{
s = thin;
}else if(t > 0.2)
{
s= thin_much;
}
}
switch(s)
{
case normal:
cout<<"Congratulations,your are in good healthy and your heavy is normal!";break;
case thin_much:
cout<<"I am so sorry to tell you that you are too thin.";break;
case thin:
cout<<"Ohh...It's a little thin for you.";break;
case fat:
cout<<"I am sorry that you are a little fat and you should exercise more.";break;
case fat_much:
cout<<"Oh my god!I think you should eat vegetables more and take much exercise!";break;
}
cout<<endl;
}


运行结果

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: