为什么我的scanf不接受我的选择并通过循环?

jm81lzqq  于 2022-12-11  发布在  其他
关注(0)|答案(1)|浏览(130)

每当我输入数字1时,它就不断地遍历print_menu();得双曲余切值.
如果choice是== to 1,我希望while循环会继续执行if语句,但它没有。它一直打印菜单。事实上,如果我输入任何数字,它都会打印菜单。

while (run_game==TRUE) {
        print_menu();
        scanf("%d", &choice);
        choice = choice1;
        if (choice1 == 1) {
            while (hands<10);
            shuffle(card_deck);
            deal(card_deck, face, suit);
            print_hand(face, suit, p1_hand);
            printf("You have these cards in your hand:\n");
            p1_score = check_hand(p1_hand);
            p2_score = check_hand(p2_hand);
            printf("Player one has :%d points", p1_score);
            printf("Redraw card?\n 1.Yes, 2. No");
            scanf("%d", &ans);
            if (ans == 1) {
                while (ans > 3) {
                    print_hand(face, suit, p1_hand);
                }
            }
        }
    }
}
qnyhuwrf

qnyhuwrf1#

你是想把scanf变成choice1吗?

scanf("%d", &choice1);

如果不是,那么下一行将覆盖choice,并且它将始终是choice1开始时的内容。

相关问题