输入a b c q 会有对应响应,但是第一次输入a没有对应响应,第二次输入a才有对应响应?

#include <stdio.h>
char get_choice(void);
char get_frist(void);

int main(void)
{
    int choice;

    while ((choice = get_choice()) != 'q')
    {
        switch (choice)
        {
        case 'a':
            printf("Buy low, sell high.\n");
            break;
        case 'b':
            putchar('\a');
            break;
        case 'c':
            putchar('\a');
            break;
        default:
            printf("Promgram is error.\n");
            break;
        }
        printf("Bye!\n");

        return 0;
    }

    return 0;
}

char get_choice(void)
{
    int ch;
    printf("Enter the letter of your choice:\n");
    printf("a. advice          b. bell\n");
    printf("c. count           q. quit\n");
    ch = get_frist();
    while ((ch < 'a' || ch > 'c') && ch != 'q');
    {
        printf("Please respond with a, b, c, q\n");
        ch = getchar();
    }
    return ch;
}

char get_frist(void)
{
    int ch;
    ch = getchar();
    while (getchar() != '\n')
        continue;

    return ch;
}

你的代码第41行while循环后面多了个;


#include <stdio.h>
char get_choice(void);
char get_frist(void);
int main(void)
{
    int choice;
    while ((choice = get_choice()) != 'q')
    {
        switch (choice)
        {
        case 'a':
            printf("Buy low, sell high.\n");
            break;
        case 'b':
            putchar('\a');
            break;
        case 'c':
            putchar('\a');
            break;
        default:
            printf("Promgram is error.\n");
            break;
        }
        printf("Bye!\n");
        return 0;
    }
    return 0;
}
char get_choice(void)
{
    int ch;
    printf("Enter the letter of your choice:\n");
    printf("a. advice          b. bell\n");
    printf("c. count           q. quit\n");
    ch = get_frist();
    while ((ch < 'a' || ch > 'c') && ch != 'q')
    {
        printf("Please respond with a, b, c, q\n");
        ch = getchar();
    }
    return ch;
}
char get_frist(void)
{
    int ch;
    ch = getchar();
    while (getchar() != '\n')
        continue;
    return ch;
}

img