giving 1 second to press 'g'

Hi

I'm making a small game and I need a way to give the player 1 second to press 'g' (and maybe 'enter' afterwards).
/*I use Borland 2006 and I code in a mix of C and C++*/
/*I'm compiling it to be a simple .exe file*/

Here's what I've done:
I found 2 fonction to give me time.
wait();
or
sleep();
I can use them correctly.

I've tried many different variations of the same concept:

/*not actual code*/
1
2
3
4
5
6
7
cout<<"g";  //to let the user know I want the caracter 'g'
wait(1 second);
cin>>x;
if x == what I want
  A();
else
  B();


The problem is that whether I use cin, getchar, or scanf the computer always waits for the input.
My idea was to wait, then if x = g do A if not, do B. But I want to force the user to input g while the program is waiting.

Is there a function that gives you a certain amount of time to input a value?
Or a way to time out a function like getchar?
A maybe a way to count the time it takes to input 'g',then comparing the time to a value to decide if it was fast enough?

Or anything else ?

Thanks
I suggest you look here: http://www.cplusplus.com/reference/clibrary/ctime/
This is the time library, what you could do is like this:
output "g"
get current time & set it to a value (curtime for example)
input your x
once they've pressed enter (ie, after the cin>>x;) check the time & set that to a value (nextime for example)
then measure the difference between them & put it in an if statement.
Hope that helps.
I works, thanks!
Topic archived. No new replies allowed.