求大神,这道入门编程题用c++怎么编啊...
1个回答
展开全部
#include<iostream>
using namespace std;
void main()
{
char sex,sports,diet;
float faHeight,moHeight,Height;
cout<<"请输入性别代码:"<<endl;
cin>>sex;
if(sex=='F')
{
cout<<"请问喜欢运动吗?"<<endl;
cin>>sports;
if(sports=='Y')
{
cout<<"请问饮食习惯良好吗?"<<endl;
cin>>diet;
if(diet=='Y')
{
cout<<"请输入父母的身高:"<<endl;
cin>>faHeight>>moHeight;
Height=(faHeight+moHeight)*0.54*(1+0.02)*(1+0.015);
cout<<"身高="<<Height<<endl;
}
else if(diet=='N')
{
cout<<"请输入父母的身高:"<<endl;
cin>>faHeight>>moHeight;
Height=(faHeight+moHeight)*0.54*(1+0.02);
cout<<"身高="<<Height<<endl;}
else cout<<"错误,输入了错误的信息!"<<endl;
}
else if(sports=='N')
{
cout<<"请问饮食习惯良好吗?"<<endl;
cin>>diet;
if(diet=='Y')
{
cout<<"请输入父母的身高:"<<endl;
cin>>faHeight>>moHeight;
Height=(faHeight+moHeight)*0.54*(1+0.015);
cout<<"身高="<<Height<<endl;
}
else if(diet=='N')
{
cout<<"请输入父母的身高:"<<endl;
cin>>faHeight>>moHeight;
Height=(faHeight+moHeight)*0.54;
cout<<"身高="<<Height<<endl;.
}
else cout<<"错误,输入了错误的信息!"<<endl;
}
else cout<<"错误,输入了错误的信息!"<<endl;
}
else if(sex=='M')
{
cout<<"请问喜欢运动吗?"<<endl;
cin>>sports;
if(sports=='Y')
{
cout<<"请问饮食习惯良好吗?"<<endl;
cin>>diet;
if(diet=='Y')
{
cout<<"请输入父母的身高:"<<endl;
cin>>faHeight>>moHeight;
Height=(faHeight*0.923+moHeight)/2*(1+0.02)*(1+0.015);
cout<<"身高="<<Height<<endl;
}
else if(diet=='N')
{
cout<<"请输入父母的身高:"<<endl;
cin>>faHeight>>moHeight;
Height=(faHeight*0.923+moHeight)/2*(1+0.02);
cout<<"身高="<<Height<<endl;
}
else cout<<"错误,输入了错误的信息!"<<endl;
}
else if(sports=='N')
{
cout<<"请问饮食习惯良好吗?"<<endl;
cin>>diet;
if(diet=='Y')
{
cout<<"请输入父母的身高:"<<endl;
cin>>faHeight>>moHeight;
Height=(faHeight*0.923+moHeight)/2*(1+0.015);
cout<<"身高="<<Height<<endl;
}
else if(diet=='N')
{
cout<<"请输入父母的身高:"<<endl;
cin>>faHeight>>moHeight;
Height=(faHeight*0.923+moHeight)/2;
cout<<"身高="<<Height<<endl;
}
else cout<<"错误,输入了错误的信息!"<<endl;
}
else cout<<"错误,输入了错误的信息!"<<endl;.
}
else cout<<"错误,输入了错误的信息!"<<endl;
}
以上程序,经过测试,没有问题。
PS:::不懂还可继续问。。。
追问
如果用c语言要怎么写?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询