setting time.

Hi, I would like to ask another question. How can I set a time limit for a certain function. For example, I want the user to answer as many mathematics questions in 60 seconds. How can I set the time limit by using difftime(time_t 1, time_t 2)?
You can't set the time a function is allowed to execute for. The conventional way to do that is to call some function within a timer loop.

The psuedo code is:
1
2
3
4
    ask question
    set count-down timer start value
    while (time not expired) AND (user not answered)
        check for user answer

The while loop is a pre-check. If there's a notion of pausing (like with the normal std::cin and similar), I'd go for multi threading or post-checks, like with do-while rather than while.
but how am I going to set a condition for (user not answered)? What should I write for that?
You call some function that checks for keypress. It rerturns something to indicate its state and you have to manage its state. For example, accepting a value, redoing an answer and so on.

That complexity is the price you pay for being interruptable.
Topic archived. No new replies allowed.