이것은 이전 게시물의 동일한 게임입니다 (링크는 Here입니다). 그 게시물의 제목은 "C++ Clock Not Working"이었고 나는 시계를 고정 시켰습니다, "Hooray!". 이제는 지속 시간을 계산하기 위해 사용하는 프로세스가 중단 된 것 같습니다. 나는 항상 'x.y'e-05'를 얻는다. 여기서 시간은 초 안에 있어야하지만 타이머는 'x.y'e-05'보다 먼저 멈춘다. 또한 05는 그것이 기초 8에 있다는 것을 의미합니까? 그렇다면 왜 ???내 간단한 게임의 타이머가 매우 꺼져 있습니다 ... C++
방금 누락 된 매우 간단한 해결책이 있습니다.
do {
//Procedere For Each Round
clock_t start;
//Clock
start = clock();
cout<<"The number is: "<< actualNumber<<endl;
getline(cin, numberGuessed);
intNumberGuessed = stoi(numberGuessed);
clock_t finish;
finish = clock();
double elapsed = (double)(finish-start);
duration = elapsed/CLOCKS_PER_SEC;
cout<<"The Duration Is: "<< duration<<endl; //FOR TESTING...
//Test User's input
//timeForInput is chosen earlier and is either 1,2,or 5.
if((intNumberGuessed == actualNumber) && (duration <= (timeForInput/100000))){
score += 1;
gameOver = 0;
} else if ((intNumberGuessed != actualNumber) || (duration >= (timeForInput/100000))) {
gameOver = 1;
}
//Reset Number
actualNumber = rand() % 4 + 1;
//Reset Clock
} while (gameOver != 1);
}
cout<<"You Failed!"<<endl;
sleep(1);
cout<<"Your Score Was: "<<score<<endl;
return 0;