Help in making a countdown timer

Hey frns

I'm creating a game in which i.need player to.answer.my question within 10 seconds...
So i.need a code for this timer...
I dont want code to be paused by sleep or delay functions..
But i need that it waits.for 10 seconds.. and if user types answer in between.. it.reads it

And if player.doesn't answers it within 10 sec.. it displays a message
Can you give more details? What development environment / libraries are you using?

The following thread might be of interest for you:
http://www.cplusplus.com/forum/beginner/317/

(But if you use some libraries already, there might be build in timers that you should use instead writing your own timer!)

With kind regards,

Konrad
If you don't want the timer to block the user input, you're going to have to run it on a separate thread. Have you used threads before?

The details depends on:

1. do you have a compiler that supports C++11 -- allowing you to use std::thread

2. otherwise you will have to using the system's native threading or obtain the Boost library for their version of the thread class, so we need to know what operating system you are writing for.

To test for std::thread, see if this code in this post compiles:

calling std::thread throws std::system_error
http://www.cplusplus.com/forum/general/57703/

(If you are using GCC, you will have to enable C++11 features by adding -std=c++0x to your g++ command line. Or -std=c++11 if you're using GCC 4.7 or later.

If Visual C++, you neeed to change __func__ to _FUNCTION_)

Andy

PS There are ways round the threading issue if you use system calls, but that would mean writing you own input routines rather than using cin. These are more complicated than the thread solution.
Last edited on
Topic archived. No new replies allowed.