m0_70250303 2022-05-06 21:17 采纳率: 70%
浏览 22
已结题

为啥输出结果一直是零?求看看

#include<stdio.h>
int main()
{ char sex,sports,diet;
float height,moheight,faheight;
scanf ("性别:%c 父亲身高:%f 母亲身高:%f 是否喜欢运动:%*c%c 是否有良好饮食习惯:%c%c",&sex,&faheight,&moheight,&sports,&diet);
if (sex == 'M')
{
if (sports == 'Y' && diet == 'Y')
{
height = (faheight + moheight) * 0.54 * (1 + 0.035);
}
else if (sports == 'Y' && diet == 'N')
{
height = (faheight + moheight) * 0.54 * (1 + 0.02);
}
else if (sports == 'N' && diet == 'Y')
{
height = (faheight + moheight) * 0.54 * (1 + 0.015);
}
else if (sports == 'N' && moheight == 'N')
{
height = (faheight + moheight) * 0.54;
}
}
if (sex == 'W')
{
if (sports == 'Y' && diet == 'Y')
{
height=((faheight * 0.923 + moheight) / 2 )
(1 + 0.035);
}
else if (sports == 'Y' && diet == 'N')
{
height = ((faheight * 0.923 + moheight) / 2) * (1 + 0.02);
}
else if (sports == 'N' && diet == 'Y')
{
height = ((faheight * 0.923 + moheight) / 2) * (1 + 0.015);
}
else if (sports == 'N' && moheight == 'N')
{
height = ((faheight * 0.923 + moheight) / 2);
}
}
printf("你的身高:%.0fcm",height);
}

  • 写回答

1条回答 默认 最新

  • A-Chin 2022-05-06 21:26
    关注

    scanf ("性别:%c 父亲身高:%f 母亲身高:%f 是否喜欢运动:%*c%c 是否有良好饮食习惯:%c%c",&sex,&faheight,&moheight,&sports,&diet);
    用法不对,改成这样:
    scanf ("%c%f%f%c%c",&sex,&faheight,&moheight,&sports,&diet);
    提示语用 printf 输出

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 5月15日
  • 已采纳回答 5月7日
  • 创建了问题 5月6日

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?