问题及代码:
/*
*Copyright (c)2014,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:weight.cpp
*作 者:夏焕哲
*完成日期:2014年12月19日
*版 本 号:v1.0
*
*问题描述:根据身高体重,计算体重是否合格。
*程序输入:姓名、性别、身高、体重。
*程序输出:判断结果。
*/
#include <iostream>
using namespace std;
struct health
{
char name[20];
char sex;
double height;
double weight;
};
int main()
{
double tizhong,difference;
health people;
cout<<"请输入姓名、性别(男人为m,女人为f)、身高(cm)和体重:";
cout<<endl;
cin>>people.name>>people.sex>>people.height>>people.weight;
if(people.sex=='m')
{
tizhong=(people.height-80)*0.7;
difference=people.weight-tizhong;
if(difference<0)
{
difference=difference*(-1);
if(difference<=tizhong*0.1)
cout<<"恭喜,你的体重正常。";
else if(tizhong*0.1<difference<=tizhong*0.2)
cout<<"同学,该练练肌肉,涨涨体重了了,为了追女神!";
else if(difference>tizhong*0.2)
cout<<"同学,苗条是女人的事,男的应该有强壮的身躯和臂膀,为心中的那个她遮挡风雨,平时多吃点。";
}
else
{
if(difference<=tizhong*0.1)
cout<<"恭喜,你的体重正常。";
else if(tizhong*0.1<difference<=tizhong*0.2)
cout<<"同学,该减肥了,为了女神!";
else if(difference>tizhong*0.2)
cout<<"同学,你必须减肥了,为了以后战胜高富帅,迎娶白富美,奋斗。";
}
}
if(people.sex=='f')
{
tizhong=(people.height-80)*0.7;
difference=people.weight-tizhong;
if(difference<0)
{
difference=difference*(-1);
if(difference<=tizhong*0.1)
cout<<"美女,你的体重正常。";
else if(tizhong*0.1<difference<=tizhong*0.2)
cout<<"美女,别老减肥,他会担心的";
else if(difference>tizhong*0.2)
cout<<"美女,现在流行健康美,你太瘦了,小心错过心中的他。";
}
else
{
if(difference<=tizhong*0.1)
cout<<"美女,你的体重正常。";
else if(tizhong*0.1<difference<=tizhong*0.2)
cout<<"同学,该减肥了。";
else if(difference>tizhong*0.2)
cout<<"同学,你必须减肥了,为了以后让高富帅对你恋恋不舍,死心塌地,努力减肥,奋斗。";
}
}
return 0;
}
运行结果: