1

When I run below code it works until 3 iterations of simple game but after the 3rd iteration CPU usage shoots to 90% and instantly crashes. Even console is terminated but below programs exe is seen in windows task list. I have to manually delete it for windows CPU to return to 3% levels. Do you know what causes this? (I use Dev-C++ on windows 7 64 bit machine)

#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