Sign in with
Sign up | Sign in
Your question
Solved

Timer in a C++ program

Last response: in Applications
Share
February 17, 2012 12:09:28 PM

i want to make a program of timed quiz (just like KBC).
I want to make a timer in this program.

Working of program
program will ask a question from the user and will show 4 options and will wait for user to enter a option, if user is not able to answer or is not providing any input then in 30 seconds program will display a message of 'gameover'.

So how to introduce this timer in a C++ program?
Please give me the codding of this timer (only need coding of timer).

More about : timer program

February 17, 2012 1:59:49 PM

truegenius said:
i want to wake a program of timed quiz (just like KBC).
I want to make a timer in this program.

Working of program
program will ask a question from the user and will show 4 options and will wait for user to enter a option, if user is not able to answer or is not providing any input then in 30 seconds program will display a message of 'gameover'.

So how to introduce this timer in a C++ program?
Please give me the codding of this timer (only need coding of timer).


All it takes i a quick reference search:

http://www.cplusplus.com/reference/clibrary/ctime/clock...
http://www.cplusplus.com/reference/clibrary/ctime/time/

Because this looks like some sort of homework, I will not code it for you, just give you pointers and references so you can learn.
m
0
l
February 24, 2012 2:36:01 PM

those links are explaining how to use clock and time.
but i need to know that how to give input in-between that countdown.

it is not my homework so you can freely provide me some codding on how to accept input from user in-between that countdown.
m
0
l
Related resources
a b L Programming
February 24, 2012 2:41:02 PM

Timers tend to be dependent on the OS. What OS are you targetting and which C++ compiler are you using?
m
0
l
February 24, 2012 3:07:33 PM

borland turboc v3.0 on windows 7 ultimate 32bit
m
0
l
a b L Programming
February 24, 2012 3:21:54 PM

I'm afraid that, as far as I know, there is no way to do this using Turbo C. (well, never say never, but it would certainly be extremely difficult if it is possible). It is a very old compiler and cannot produce multithreaded code, or call the Windows APIs, which is what you really need.

This would be trivial if you were using a compiler that could access the Windows API, such as Visual C++. Turbo C was a fine language in its day, but that day is long past. I am constantly amazed by the number of people still using Turbo C when there are so many more modern compilers available.

Edit - on second thoughts, I believe that Turbo C had a delay() function. So write a loop that checks for a keypress, does a one-second delay and increments a counter. Exit the loop when a key is pressed or the router reaches, say, 30. It's not very clean or accurate, but should work. I'll leave you to fill in the details.
m
0
l
February 24, 2012 4:11:57 PM

"checks for a keypress"+ 'in between that countdown' thats the exact thing that i want to do but don't know how to.

i too have visual c++ and borland turbo c v4.5 windows.
m
0
l

Best solution

a b L Programming
February 24, 2012 4:35:00 PM

I believe there is a function kbhit() in Turbo C that checks if a key has been pressed.

If you want to use Visual C++ then Googling "Windows Timer" should give you plenty of hits explaining how to use timers in Windows.
Share
March 6, 2012 9:02:34 AM

kbhit() seems close to the function that i want, i tried it to use it but unable to make it work as i don't know much, so i am still waiting for more hint or program.
m
0
l
March 25, 2012 11:38:58 AM

hey guys, you forget about me
it is not my home work
it is a part of a series of many games that i want to make, and i want to know how to do this thing as it is common in my games.
m
0
l
March 4, 2013 2:39:42 AM

Best answer selected by truegenius.
m
0
l
!