Timer use?

This is a discussion on Timer use? within the C++ Programming forums, part of the General Programming Boards category; I'm writing a program for my 2nd grade daughter. She has to do 100 math problems in 2 min's for ...

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

    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.

    Thanks

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

    Code:
    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
    
    while(loop)
    {
    	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
    Location
    Freeport, IL
    Posts
    32
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21