以下のコードを DevC++ (TDM-GCC 4.6.1.64 コンパイラを使用するバージョン 4.9.9.2 Orwell Update 5.3.0.3) で実行すると、単純なゲームの 3 回の反復までは機能しますが、3 回目または 4 回目の反復の後、CPU 使用率は 90% に達し、即座に発生します。クラッシュします。コンソールも終了しますが、プログラムの下にexeがWindowsタスクリストに表示されます。Windows CPU が 3% レベルに戻るには、手動で削除する必要があります。
しかし、このコードを Windows Visual Studio 2008 Professional で実行すると、問題なく動作します。何が原因か知っていますか?(私のコンピューターは Windows 7 64 ビット マシンです)
私は DevC++ が大好きで、それを使いたいと思っています。私はVisual Studioが好きではありません。しかし、プログラムが頻繁にクラッシュする場合 (コードが間違っているのかもしれませんが、このコードは Visual Studio で動作しますか??) 今後は Visual Studio を使用する必要があります。
答えてください。私の DevC++ に欠陥があるのでしょうか?
#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,aha;
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",&aha);
choice=aha;
printf("Hmm you wanna play again...\n");
}
printf("Program is terminated.");
}