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)?
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.
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.