问答详情
源自:4-2 分支结构之简单if-else语句

为什么这个代码运行到最后输出不了结果就结束了

#include<stdio.h>
int main(void)
{
float Height;
float faHeight;
float moHeight;
char sex;
char sport;
char diet;
printf("Are you a boy(m) or a girl(f)\n");
scanf(" %c",&sex);
printf("please enter your father's height\n");
scanf("%f",&faHeight);
printf("please enter your mother's height\n");
scanf("%f",&moHeight);
if(sex=='f'||sex=='F')
{
    Height=(faHeight+moHeight)*0.54;
    
}
else
{
        Height=(faHeight*0.923+moHeight)/2;
}


printf("do you have a good diet(y/n)\n");
scanf(" %c",&diet);
if(diet=='y'||diet=='Y');
{
    Height = Height*1.015;
}
printf("do you like sport(y/n)\n");
scanf(" %c",sport);
if(sport=='y'||sport=='Y')
{
    Height = Height*1.02;
}
printf("your future Height will be %f\n",Height);
return 0;

}

提问者:qq_涵雨_jmEU57 2018-10-25 14:58

个回答

  • NuMbing
    2018-10-25 21:39:47
    已采纳

    倒数第7行,sport没有取地址。加一个&