0

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

secretgenes
  • 1,291
  • 1
  • 19
  • 39
Demosblas
  • 21
  • 2

1 Answers1

1

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?

Community
  • 1
  • 1
Benedikt S. Vogler
  • 554
  • 1
  • 5
  • 19