我将下面的代码作为C程序的一部分来更改方向。每当我运行代码时,输出总是大小写,后跟默认值。为什么会发生这种情况,如何停止每次显示的默认设置?
谢谢
输出示例:
输入命令:W
对不起,您不能那样走。请输入另一个方向: 抱歉,这不是方向。请输入N,E,S或W:
printf("\nEnter command:"); while (1) {
scanf_s("%c", &ch);
switch (ch)
{
case 'w':
case 'W':
printf("\nSorry, You can't go that way. Please enter another direction:");
break;
case 's':
case 'S':
printf("\nSorry, You can't go that way. Please enter another direction:");
break;
case 'e':
case 'E':
printf("\nSorry, You can't go that way. Please enter another direction:");
break;
case 'n':
case 'N':
case 'q':
case 'Q':
printf("Goodbye!\n");
exit(0);
default:
printf("\nSorry, that's not a direction. Please enter either N, E, S or W:");
break;
}
}