#include <iostream>
using namespace std;
struct Text
{
char name[10];
char sex;//M表示男性,W表示女性
int hight;
int weight;
};
int main()
{
double t,over;
Text T;
cin>>T.name>>T.sex>>T.hight>>T.weight;
if(T.sex=='M')
t=(T.hight-80)*0.7;
else
t=(T.hight-70)*0.6;
over=(T.weight-t)/t;
if(over>0.2)
cout<<"您该减肥啦!";
else if(over>0.1)
cout<<"您的体重偏重。";
else if(over>-0.1)
cout<<"您的体重很标准!";
else if(over>-0.2)
cout<<"您的体重偏轻。";
else
cout<<"您太轻了,小心被风吹走啊!";
return 0;
}
运行结果:
总结:
运用了结构体的知识,主要注意结构体输入时要一项一项地根据顺序列出来,还有这个程序里将偏重值计算出来与公式中给出的值比较,这样简单明了。