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日