I'm writing a code where the user has to answer the question in 10 seconds or else he will lose, I know that I'm supposed to use threads but the problem is, I don't know how to do the timer, any ideas?
Thanks
I'm writing a code where the user has to answer the question in 10 seconds or else he will lose, I know that I'm supposed to use threads but the problem is, I don't know how to do the timer, any ideas?
Thanks
You don't need threads.
Assuming time is in ms:
updateLoop(){
timeLeft = startingTime + 10.000 - now;
if (timeLeft <= 0) {
lose=true;
}
render();
}
EDIT: I probably misunderstood the question a bit. This seems to cover your question, as in @Mourad's comment: How to use a timer in C++ to force input within a given time?