Djanvk wrote:
Ok I'm working on a program where you have say x number of seconds to
do something. I'm at a loss on how to go about running a timer
function. Can anyone point me in the right direction or post a
snippet of code for me to look at?
The program I'm trying to write is a 2nd grade math program to help my
daughter with her addition and subtraction.
If you try to do it the way I think you want, you will get into
serious troubles.
What I think you want to implement is this:
program outputs an assignement
a timer is started and the program waits for an input
Now 2 things are possible
* the timer expires, in which case the assignment counts as not done
* an input is given
...
Well. The point I am heading at is, that in order to implement it that way
ou need some sort of interruptable input function. That is something C++
does not provide out of the box. Also: What should happen, if the user
starts typing and that timer interrupt occours? Does the answer count
(because eg. your daughter is just a slower typer and spends half of
her time in searching for the keys), or does it not count?
For simplicity I would suggest some slightly change
program outputs an assignement
program saves the current time
program waits for input
-> (user enters his answer)
program gets the current time and compares it with the
previously stored time. If more then x seconds have passed,
the answer is not counted.
program checks the answer ...
For this you only need a function that gives you the current time.
Look up the functions in
#include <ctime>
(the C header would be: #include "time.h" )
It contains everything you need to implement this strategy.
--
Karl Heinz Buchegger
kb******@gascad.at