I'm writing a program for my 2nd grade daughter.
She has to do 100 math problems in 2 min's for her class. Now the programming problem I have is how to create a timer that will stop placing new math problems up after 2 mins or any other x number of seconds.
Can anyone help here.
You can use funtcion time() defined in <ctime>. Use this function with a NULL argument (or 0) to return the current time in seconds.
Here's a little trick that could check for the elapsed time ( its not 100% accurate in timing though ):
This will stop asking the questions within the loop after 20 seconds , which is what you want , but she can take her time on the last question though.
bool loop = true; // loop variable
int current = time(0); // get time in seconds
int finish = current + 20; // specify deadline wich is current
// time plus 20 seconds
current = time(0); // update current time
// ask questions and investigate answers here
if(finish < current)
loop = false;
// if deadline is less than current time ; it means the
// time's out and we should terminate the "questions loop"
hope this helps :)
Perfect, thats what I was looking for...