#include <stdio.h>
int main()
{
char sex,sports,diet;
float faHeight,moHeight,chilHeight;
printf("请输入您的性别,女性输F,男性输M:");
sex=getchar();
printf("请输入您父亲的身高(厘米)faHeight=,母亲的身高(厘米)moHeight=",faHeight,moHeight);
scanf("%f %f",&faHeight,&moHeight);
printf("您是否喜欢体育锻炼,“是”请输入Y,“不是”请输入N,%c\n");
sports=getchar();
printf("您的饮食习惯是否健康,“是”请输入Y,“不是”请输入N,%c\n");
diet=getchar();
if(sex=='M')
{
if(sports=='Y'&&diet=='Y')
{chilHeight=(faHeight+moHeight)*0.54*(1+0.02+0.015);
}
else if(sports=='Y'&&diet=='N')
{chilHeight=(faHeight+moHeight)*0.54*(1+0.02);
}
else if(sports=='N'&&diet=='Y')
{chilHeight=(faHeight+moHeight)*0.54*(1+0.015);
}
else if(sports=='N'&&diet=='N')
{chilHeight=(faHeight+moHeight)*0.54;
}
printf("您未来的身高chilHeight=%f\n",chilHeight);
}
else if(sex=='F')
{
if(sports=='Y'&&diet=='Y')
{chilHeight=((faHeight*0.923+moHeight)/2)*(1+0.02+0.015);
}
else if(sports=='Y'&&diet=='N')
{chilHeight=((faHeight*0.923+moHeight)/2)*(1+0.02);
}
else if(sports=='N'&&diet=='Y')
{chilHeight=((faHeight*0.923+moHeight)/2)*(1+0.015);
}
else if(sports=='N'&&diet=='N')
{chilHeight=((faHeight*0.923+moHeight)/2)*(1+0.02+0.015);
}
printf("您未来的身高chilHeight=%f\n",chilHeight);
}
return 0;
}
想问一下大佬们,这个程序哪里出了问题,导致我最后的结果不对,我感觉从Y,N输入就有问题,可我没找出来
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
5条回答 默认 最新
- sinJack 2021-04-23 10:19关注
#include <stdio.h> #define N 2 int main() { char sex[N],sports[N],diet[N]; float faHeight,moHeight,chilHeight; printf("请输入您的性别,女性输F,男性输M:"); scanf("%s",sex); printf("请输入您父亲的身高(厘米)faHeight=,母亲的身高(厘米)moHeight="); scanf("%f %f",&faHeight,&moHeight); printf("您是否喜欢体育锻炼,“是”请输入Y,“不是”请输入N\n"); scanf("%s",sports); printf("您的饮食习惯是否健康,“是”请输入Y,“不是”请输入N\n"); scanf("%s",diet); if(sex[0]=='M') { if(sports[0]=='Y'&&diet[0]=='Y') {chilHeight=(faHeight+moHeight)*0.54*(1+0.02+0.015); } else if(sports[0]=='Y'&&diet[0]=='N') {chilHeight=(faHeight+moHeight)*0.54*(1+0.02); } else if(sports[0]=='N'&&diet[0]=='Y') {chilHeight=(faHeight+moHeight)*0.54*(1+0.015); } else if(sports[0]=='N'&&diet[0]=='N') {chilHeight=(faHeight+moHeight)*0.54; } printf("您未来的身高chilHeight=%f\n",chilHeight); } else if(sex[0]=='F') { if(sports[0]=='Y'&&diet[0]=='Y') {chilHeight=((faHeight*0.923+moHeight)/2)*(1+0.02+0.015); } else if(sports[0]=='Y'&&diet[0]=='N') {chilHeight=((faHeight*0.923+moHeight)/2)*(1+0.02); } else if(sports[0]=='N'&&diet[0]=='Y') {chilHeight=((faHeight*0.923+moHeight)/2)*(1+0.015); } else if(sports[0]=='N'&&diet[0]=='N') {chilHeight=((faHeight*0.923+moHeight)/2)*(1+0.02+0.015); } printf("您未来的身高chilHeight=%f\n",chilHeight); } return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥65 永磁型步进电机PID算法
- ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
- ¥88 找成都本地经验丰富懂小程序开发的技术大咖
- ¥15 如何处理复杂数据表格的除法运算
- ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
- ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
- ¥15 latex怎么处理论文引理引用参考文献
- ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
- ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
- ¥15 乘性高斯噪声在深度学习网络中的应用