一道用C语言做的题 会的大哥帮帮忙啊!

2024-12-21 22:25:05
推荐回答(3个)
回答1:

我写了一个比较简单的,你可以参考下,不懂的可以PM我。
#include
double getnumber(char sex,char sport,char diet,double fH,double mH)//计算身高的公式
{
double cH;//孩子的身高

if(sex=='M')//判断性别

{
cH=(fH+mH)*0.54;//若是男孩子
}
else
{
cH=(fH*0.923+mH)/2 ;//若是女孩子
}
if(sport=='Y')//判断是否经常锻炼
{
cH=cH*(1+0.02);
if(diet=='Y')//判断是否健康饮食
{
cH=cH*(1+0.015);
return cH;
}
else return cH;
}
else return cH;
}

void main()
{
char sex,sport,diet;
double fH,mH;
cout<<"请依次输入sex,fH,mH,sport,diet参数"<cout<<"sex:"<cin>>sex;
cout<<"fH:"<cin>>fH;
cout<<"mH:"<cin>>mH;
cout<<"sport:"<cin>>sport;
cout<<"diet:"<cin>>diet;
cout<<"孩子身高为:"<}

回答2:

应该问你同学的。
C++我不会 ,路过 相信有人能帮你的。

回答3:

等桌!!我去编写来给你!!!C语言能搞定!!!
#include
#include
main()
{float mH,fH,MH,FH;
char sex,sports,diet;
printf("Please input sex M or F:");
scanf("%c",&sex);
printf("Please input sports Y or N:");
scanf("%c",&sports);
printf("Please input diet Y or N:");
scanf("%c",&diet);
printf("Please input mH,fH:");
scanf("%f,%f",&mH,&fH);
if(sex=='M'&&sports=='Y'&&diet=='Y')
{MH=((fH+mH)*0.54)*1.035;
printf("MH=%f\n",MH);
getch();}
if(sex=='M'&&sports=='Y'&&diet=='N')
{MH=((fH+mH)*0.54)*1.02;
printf("MH=%f\n",MH);
getch();}
if(sex=='M'&&sports=='N'&&diet=='Y')
{MH=((fH+mH)*0.54)*1.015;
printf("MH=%f\n",MH);
getch();}
if(sex=='M'&&sports=='N'&&diet=='N')
{MH=(fH+mH)*0.54;
printf("MH=%f\n",MH);
getch();}
if(sex=='F'&&sports=='Y'&&diet=='Y')
{FH=((fH*0.923+mH)/2)*1.035;
printf("FH=%f\n",FH);
getch();}
if(sex=='F'&&sports=='Y'&&diet=='N')
{FH=((fH*0.923+mH)/2)*1.02;
printf("FH=%f\n",FH);
getch();}
if(sex=='F'&&sports=='N'&&diet=='Y')
{FH=((fH*0.923+mH)/2)*1.015;
printf("FH=%f\n",FH);
getch();}
if(sex=='F'&&sports=='N'&&diet=='N')
{FH=(fH*0.923+mH)/2;
printf("MH=%f\n",MH);
getch();
}
}
楼下的改下。我这个好像哪个地方有问题,输入的时候sports找不到入口,和后面的diet同时冒出来!!!