Switch语句输出大小写,后跟默认值

时间:2019-04-12 19:26:56

标签: c

我将下面的代码作为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;
    }
}

0 个答案:

没有答案