我正在尝试将 if/else 嵌套在 case switch 语句中。当我输入 case 'p' 或 'P' 时,无论输入什么字符,都会打印 $15.00 行。我尝试移动/添加 {},但输出没有变化。
感谢您花时间帮助菜鸟。
整个代码现在在这里。
#include <stdio.h>
int main()
{
//variable declarations
char typeOfWash, tireShine;
//Menu
printf("R ---> Regular ($5.00)\n");
printf("B ---> Bronze ($7.50)\n");
printf("G ---> Gold ($10.25)\n");
printf("P ---> Platinum ($15.00)\n");
printf("Tire Shine can be added to the Gold or Platinum ONLY,");
printf("for an additional$2.50\n\n");
printf("Enter your selection: ");
scanf("%c",&typeOfWash);
switch (typeOfWash)
{
case 'R': case 'r':
printf("Your bill total is: $5.00\n");
break;
case 'B': case 'b':
printf("Your bill total is: $7.50\n");
break;
case 'G': case 'g':
printf("Would you Like a Tire Shine? (Y/N): ");
scanf("%c ",&tireShine);
if (tireShine == 'Y' || tireShine == 'y')
printf("Your bill total is: $12.75\n");
else
printf("Your bill total is: $10.25\n");
break;
case 'P': case 'p':
printf("Would you Like a Tire Shine? (Y/N): ");
scanf("%c ",&tireShine);
printf("%c",tireShine);
if (tireShine == 'Y' || tireShine == 'y')
printf("Your bill total is: $17.50\n");
else
printf("Your bill total is: $15.00\n");
break;
default:
printf("Invalid Choice");
}
return 0;
}