Resetting Clock()???

This is a discussion on Resetting Clock()??? within the C++ Programming forums, part of the General Programming Boards category; Ok, i have my code: Code: int seconds; clock_t clock(); seconds = clock()/CLOCKS_PER_SEC; if (seconds == 8){ FIVE.SetPositionX(-1); } //.... ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    12

    Resetting Clock()???

    Ok, i have my code:

    Code:
    int seconds;
    	clock_t clock();
    	seconds = clock()/CLOCKS_PER_SEC;
     
    	if (seconds == 8){
    			FIVE.SetPositionX(-1);
    			}
    //....
    if ((AdventureGame.keypressed[DIK_F]) && (WOO.positionX == -10)){
     
    		//reset clock() here
    		FIVE.SetPositionX(-5);
    }
    the clock starts when the program is run and after 8 secs, FIVE moves position.
    When i press F, i want FIVE to reset its position [which it does], and to reset the clock(), so that after 8 secs, FIVE will move again.
    Anyway to do this?
    Using Windows 7, visual studio

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,750
    You can't reset the clock(), so you should use another variable to save the old value, then compare that to the latest.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical Error in Clock program
    By SVXX in forum C++ Programming
    Replies: 0
    Last Post: 05-10-2009, 01:12 AM
  2. Outside influences on clock cycles? (clock_t)
    By rsgysel in forum C Programming
    Replies: 4
    Last Post: 01-08-2009, 06:15 PM
  3. Clock Troubles
    By _Nate_ in forum C Programming
    Replies: 22
    Last Post: 06-19-2008, 06:15 AM
  4. clock program
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 11:12 PM
  5. using clock()
    By sl4nted in forum C Programming
    Replies: 8
    Last Post: 11-09-2006, 07:16 PM

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