What you are trying to do is to have an non-blocking (asynchronous) read from stdin with a timeout of 10 seconds. This is not too tough but may involve many new concepts depending on your knowledge. What we need to do is:

Place the standard input (STDIN) handle (handle = 0) into a 'watch-list'.

Place a timeout on the watch-list.

Whenever there is a change in the STDIN, process it.

When the timeout has expired, check if what we have processed does the job.

In linux, the watch-list can be handled using FD_SET and a select system call. In Windows, you will need to use WaitForMultipleEvents.

I'm not sure I can do justice to explaining these concepts accurately for the purposes of this code. As a reference, another question which has some code pointers for exactly the same thing is here.