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

为啥输出结果一直是零?求看看
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
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 输出本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用