Thread: Timer use?

  1. #1
    Registered User
    Join Date
    Mar 2005
    Freeport, IL

    Timer use?

    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.


  2. #2
    former member Brain Cell's Avatar
    Join Date
    Feb 2004
    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 ):

    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"
    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.

    hope this helps
    My Tutorials :
    - Bad programming practices in : C
    - C\C++ Tips
    (constrcutive criticism is very welcome)

    - Brain Cell

  3. #3
    Registered User
    Join Date
    Mar 2005
    Freeport, IL
    Perfect, thats what I was looking for...

    Appreciate it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SIGALRM and timer
    By nkhambal in forum C Programming
    Replies: 1
    Last Post: 06-30-2008, 12:23 AM
  2. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  3. Need help with a count down timer
    By GUIPenguin in forum C# Programming
    Replies: 0
    Last Post: 07-07-2006, 04:18 PM
  4. Timer again.
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 05-04-2005, 10:19 PM