#include <iostream>#include <string>#include <math.h>using namespace std; int eatheight(float faHeight1,float moHeight1,char sex1,char sports1){ if(sex1=='M'||sex1=='m') { if(sports1=='Y'||sports1=='y') { cout<<"男生锻炼身体+饮食良好的身高为(cm):"; cout<<(((faHeight1+moHeight1)*0.54)*0.035+((faHeight1+moHeight1)*0.54))<<"cm"<<endl; } else { cout<<"男生饮食良好的身高为(cm):"; cout<<((((faHeight1+moHeight1)*0.54)*0.015)+((faHeight1+moHeight1)*0.54))<<"cm"<<endl; } } else { if(sports1=='Y'||sports1=='y') { cout<<"女生锻炼身体+饮食良好的身高为(cm):"; cout<<((((faHeight1*0.923+moHeight1)/2)*0.035)+((faHeight1*0.923+moHeight1)/2))<<"cm"<<endl; } else { cout<<"女生饮食良好的身高为(cm):"; cout<<((((faHeight1*0.923+moHeight1)/2)*0.015)+((faHeight1*0.923+moHeight1)/2))<<"cm"<<endl; } }} int sportheight(float faHeight1,float moHeight1,char sex1){ if(sex1=='M') { cout<<"男生只锻炼身体的身高为(cm):"; cout<<((((faHeight1+moHeight1)*0.54)*0.02)+((faHeight1+moHeight1)*0.54))<<"cm"<<endl; } else { cout<<"女生只锻炼身体的身高为(cm):"; cout<<((((faHeight1*0.923+moHeight1)/2)*0.02)+((faHeight1*0.923+moHeight1)/2))<<"cm"<<endl; }} int manheight(float faHeight1,float moHeight1){ cout<<"男生正常身高为(cm):"; cout<<((faHeight1+moHeight1)*0.54)<<"cm"<<endl;} int womenheight(float faHeight1,float moHeight1){ cout<<"女生正常身高为(cm):"; cout<<((faHeight1*0.923+moHeight1)/2)<<"cm"<<endl;} int main(){ float faHeight,moHeight; char sex,sports,diet; while(1) { cout<<"请输入父亲的身高(cm):"<<endl; cin>>faHeight; cout<<"请输入母亲的身高(cm):"<<endl; cin>>moHeight; cout<<"请输入性别(M(男)/F(女)):"<<endl; cin>>sex; if(faHeight>20) if(moHeight>20) if(sex=='M'||sex=='F'||sex=='m'||sex=='f') break; else cout<<"性别输入错误,请重新输入!"<<endl<<endl; else cout<<"母亲身高输入错误,请重新输入!"<<endl<<endl; else cout<<"父亲身高输入错误,请重新输入!"<<endl<<endl; } while((sex=='M')||(sex=='F')||(sex=='m')||(sex=='f')) { while(1) { cout<<"请输入是否做体育运动(Y/N):"<<endl; cin>>sports; cout<<"请输入饮食是否良好(Y/N):"<<endl; cin>>diet; if((sports=='Y')||(sports=='N')||(sports=='y')||(sports=='n')) if((diet=='Y')||(diet=='N')||(diet=='y')||(diet=='n')) break; else cout<<"饮食输入错误,请重新输入!"<<endl<<endl; else cout<<"体育运动输入错误,请重新输入!"<<endl<<endl; } if(sex=='M') { if((sports=='Y')||(sports=='y')) if((diet=='Y')||(diet=='y')) eatheight(faHeight,moHeight,sex,sports); else sportheight(faHeight,moHeight,sex); else manheight(faHeight,moHeight); } else { if((sports=='Y')||(sports=='y')) if((diet=='Y')||(diet=='y')) eatheight(faHeight,moHeight,sex,sports); else sportheight(faHeight,moHeight,sex); else womenheight(faHeight,moHeight); } break; } system("pause"); return 0;}

评论