永发信息网

谁帮我改下代码。。。。。

答案:1  悬赏:20  手机版
解决时间 2021-05-19 06:12
  • 提问者网友:孤凫
  • 2021-05-18 10:42

#include<stdio.h>
int main(void)
{
char sex,sport,diet;

double faHeight,moHeight,kidHeight;

printf("faHeight and moHeight=%lf%lf",faHeight,moHeight);

scanf("%lf%lf",faHeight,moHeight);

printf("sex=%c",sex);

sex=getchar();

printf("sport=%c",sport);

sport=getchar();

printf("diet=%c",diet);

diet=getchar();
kidHeight=0;

switch(sex){
case'M':
if((sport=='Y')&&(diet=='N')){
kidHeight=(faHeight+moHeight)*0.54*1.02;
printf("kidHeight=%lf\n",kidHeihgt);
}
else if((sport=='N')&&(diet=='Y')){
kidHeight=(faHeight+moHeight)*0.54*1.015;
printf("kidHeight=%lf\n",kidHeight);
}
else if((sport=='Y')&&(diet=='Y')){
kidHeight=(faHeight+moHeight)*0.54*1.02*1.015;
printf("kidHeight=%lf\n",kidHeight);
}
else if((sport=='N')&&(diet=='N')){
kidHeight=(faHeight+moHeight)*0.54;
printf("kidHeight=%lf\n",kidHeight);
}
else{
printf("some of errors!\n");
}
break;
case'F':
if((sport=='Y')&&(diet=='N')){
kidHeight=(faHeight*0.923+moHeight)/2*1.02;
printf("kidHeight=%lf",kidHeight);
}
else if((sport=='N')&&(diet=='Y')){
kidHeight=(faHeight*0.923+moHeight)/2*1.015;
printf("kidHeight=%lf",kidHeight);
}
else if((sport=='Y')&&(diet=='Y')){
kidHeight=(faHeight*0.923+moHeight)/2*1.02*1.015;
printf("kidHeight=%lf",kidHeight);
}
else if((sport=='N')&&(diet=='N')){
kidHeight=(faHeight*0.923+moHeight)/2;
printf("kidHeight=%lf",kidHeight);
}
else{
printf("some of errors!\n");
}
break;
default:
printf("some of errors!\n");
break;
}
return 0;
}

为什么编译出错了。。。

最佳答案
  • 五星知识达人网友:孤独入客枕
  • 2021-05-18 12:06

有几处小错误,用你改动下,由于只是要帮你改错,故没做程序结构调整


#include<stdio.h>
int main(void)
{
char sex,sport,diet;


double faHeight,moHeight,kidHeight;


printf("请输入faHeight和moHeight,两值之间用空格区分开\n");


scanf("%lf %lf",&faHeight,&moHeight);
getchar();//用于接收缓冲区的回车符,下面的getchar用途一样


printf("请输入sex,值为M或F\n");


sex=getchar();
getchar();


printf("请输入sport,值为N或Y\n");


sport=getchar();
getchar();


printf("请输入diet,值为N或Y\n");


diet=getchar();
getchar();
kidHeight=0;


switch(sex){
case'M':
if((sport=='Y')&&(diet=='N')){
kidHeight=(faHeight+moHeight)*0.54*1.02;
printf("kidHeight=%lf\n",kidHeight);
}
else if((sport=='N')&&(diet=='Y')){
kidHeight=(faHeight+moHeight)*0.54*1.015;
printf("kidHeight=%lf\n",kidHeight);
}
else if((sport=='Y')&&(diet=='Y')){
kidHeight=(faHeight+moHeight)*0.54*1.02*1.015;
printf("kidHeight=%lf\n",kidHeight);
}
else if((sport=='N')&&(diet=='N')){
kidHeight=(faHeight+moHeight)*0.54;
printf("kidHeight=%lf\n",kidHeight);
}
else{
printf("some of errors!\n");
}
break;
case'F':
if((sport=='Y')&&(diet=='N')){
kidHeight=(faHeight*0.923+moHeight)/2*1.02;
printf("kidHeight=%lf",kidHeight);
}
else if((sport=='N')&&(diet=='Y')){
kidHeight=(faHeight*0.923+moHeight)/2*1.015;
printf("kidHeight=%lf",kidHeight);
}
else if((sport=='Y')&&(diet=='Y')){
kidHeight=(faHeight*0.923+moHeight)/2*1.02*1.015;
printf("kidHeight=%lf",kidHeight);
}
else if((sport=='N')&&(diet=='N')){
kidHeight=(faHeight*0.923+moHeight)/2;
printf("kidHeight=%lf",kidHeight);
}
else{
printf("some of errors!\n");
}
break;
default:
printf("some of errors!\n");
break;
}
return 0;
}

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯