1

当我在下面运行代码时,它一直工作到简单游戏的 3 次迭代,但在第 3 次迭代后 CPU 使用率飙升至 90% 并立即崩溃。甚至控制台也被终止,但在 Windows 任务列表中可以看到下面的程序 exe。我必须手动删除它,Windows CPU 才能恢复到 3% 的水平。你知道这是什么原因吗?(我在 Windows 7 64 位机器上使用 Dev-C++)

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void game(void);
int main(void) {
    srand(time(NULL));
    game();
    return 0;
}
void game(void) {
    int choice = 1;
    while (choice != 0) {
        int number1, number2, resultStudent, result;
        number1 = 1 + rand() % 9;
        number2 = 1 + rand() % 9;
        result = number1 * number2;
        printf("How much is %d times %d ?", number1, number2);
        scanf("%d", & resultStudent);
        while (resultStudent != result) {
            printf("No. Please try again.");
            scanf("%d", &resultStudent);
        }
        printf("Very Good\n");
        printf("Do you wanna play again?(0 for Exit):  ");
        scanf(" %d", &choice);
        printf("Hmm you wanna play again...\n");
    }
    printf("Program is terminated.");
}
4

0 回答 0