项目要求:
根据世界卫生组织推荐的体重标准,男性的标准体重=(身高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;
}
运行结果: