永发信息网

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

答案:1  悬赏:20  手机版
解决时间 2021-05-19 06:12

#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;
}

为什么编译出错了。。。

最佳答案

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


#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;
}

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
什么日韩组合的什么歌好听?
VIP5从32级升到48级要多长时间?
赎回当日是什么意思,赎回基金是按照当天赎回
找东西(纸盒子)
淮滨县信阳乐购超市这个地址怎么能查询到,着
诛仙2八十级之后是不是没诛仙任务了?
红岩佳句及赏析,红岩1到6章的名人名言
通城县咸宁龙门花甲怎么去啊,谁知道地址啊
肚脐上边是哪里?老疼是怎么回事?
私事去英国暂住一年问亲们知道手续么?~
柘城县商丘小鸟电动车地址在哪里啊
中华小当家。
头昏耳鸣是什么症状,头晕什么导致有耳鸣症状
脚趾生水秀骚痒怎么办
我的NOKIA N97和BH-320蓝牙耳机
推荐资讯
扑克牌80分玩法
阿开头的诗句,狮子老虎谁厉害
用电脑用英语怎么翻译,室内设计英语怎么说?
婴儿爱哭闹不睡觉怎么办,50天婴儿爱哭闹不睡
爱情的伤感英语句子,英语伤感爱情句子
精美文章节选,巴金散文选一个节选好词好句好
水彩笔复数英语怎么说,“水彩笔”用英语怎么
怎么收拾老公的暴脾气,如何改改自己暴躁的脾
有关告别的名言内涵,有没有关于“深处”的名
憧憬的意思是什么意思,魔兽世界单刷是什么意
在工厂里的辞职书一般怎么写 ?不会写
文员需要做什么,想当文员或秘书需要有什么证
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?