C编程错误if语句
C programming error if statement
我有这个程序,直到最后它都运行良好。当我询问用户 he/she 是否想要打折并且用户输入 y/n 时,程序只是停止并且不会转到 if 语句。有什么帮助吗?谢谢:)
int calculate(){
printf("Do you want to make a discount? y/n \n");
scanf("%c",&ask);
if (ask == 'y')
{
printf("Enter the actual money that you want to make a discount\n");
scanf("%f",&disc);
discount= (total * (disc/100));
net= (total - discount);
printf("The total bill is: %.2f\n", net);
}
else
if(ask == 'n')
{
printf("The total bill is: %.2f\n", total);
}
//menu();
return 0;
}
改变这个
scanf("%c",&ask);
至
scanf(" %c",&ask);
明确忽略任何剩余的白色 space。
我有这个程序,直到最后它都运行良好。当我询问用户 he/she 是否想要打折并且用户输入 y/n 时,程序只是停止并且不会转到 if 语句。有什么帮助吗?谢谢:)
int calculate(){
printf("Do you want to make a discount? y/n \n");
scanf("%c",&ask);
if (ask == 'y')
{
printf("Enter the actual money that you want to make a discount\n");
scanf("%f",&disc);
discount= (total * (disc/100));
net= (total - discount);
printf("The total bill is: %.2f\n", net);
}
else
if(ask == 'n')
{
printf("The total bill is: %.2f\n", total);
}
//menu();
return 0;
}
改变这个
scanf("%c",&ask);
至
scanf(" %c",&ask);
明确忽略任何剩余的白色 space。