问题及代码:
/*
*Copyright (C) 2014,烟台大学计算机学院
*All rights reserved.
*文件名称 :mian.cpp
*作 者 :李楠
*完成日期 :2014年12月17日
*版 本 号 :v1.0
*
*问题描述 :根据世界卫生组织推荐的体重标准,男性的标准体重=(身高-80)*70%,女性的=(身高-70)*60%
用结构体表示人的相关信息。
*输入描述 :三个整数
*程序输出 :三个整数
*/
#include <iostream>
using namespace std;
struct inform
{
char name[15];
char sex;
int heigh;
int weight;
};
int main()
{
double iweight,i;
inform person;
cout<<"请输入姓名、性别、身高、体重:"<<endl;
cin>>person.name>>person.sex>>person.heigh>>person.weight;
if(person.sex=='m')
{
iweight=(person.heigh-80)*0.7;
if(person.weight>iweight)
i=person.weight-iweight;
else
i=iweight-person.weight;
if((i/iweight)<=0.1)
cout<<person.name<<"先生"<<"你的体重在正常范围内哦~"<<endl;
else if((i/iweight)>0.1&&(i/iweight)<=0.2)
cout<<person.name<<"先生"<<"你有些超重啊~抓紧时间锻炼!"<<endl;
else
cout<<person.name<<"先生"<<"超重了不要紧,多锻炼,加油!"<<endl;
}
if(person.sex=='f')
{
iweight=(person.heigh-70)*0.6;
if(person.weight>iweight)
i=person.weight-iweight;
else
i=iweight-person.weight;
if((i/iweight)<=0.1)
cout<<person.name<<"女士"<<"你的体重在正常范围内哦~"<<endl;
else if((i/iweight)>0.1&&(i/iweight)<=0.2)
cout<<person.name<<"女士"<<"你有些超重啊~抓紧时间锻炼!"<<endl;
else
cout<<person.name<<"女士"<<"超重了不要紧,多锻炼,加油!"<<endl;
}
return 0;
}
运行结果:
知识点总结:
运用好了结构体类型,就能轻松地写出来,不费力~
学习心得:
无论做什么事都要有好的心态~~相信自己能行~~