clock problems

This is a discussion on clock problems within the C++ Programming forums, part of the General Programming Boards category; Is there a way to make a something happen when a time is reached, because, I tried this code, and ...

  1. #1
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154

    Question clock problems

    Is there a way to make a something happen when a time is reached, because, I tried this code, and it doesn't work at all, I think that it could be because of clock inaccuracy that is causing it...

    Code:
    #include <iostream>
    #include <stdlib.h>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
      int x;
      
      srand( (unsigned)time( NULL ) );
      x = rand() % 10;
      time_t begin;
      begin=clock();
      if(clock() == 5000)
      {
          cout << x << endl;
      }
      
      system("Pause");	
      return 0;
    }
    Any thoughts?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    Perhaps you want something like
    Code:
    while ( clock() < 5000 );  /* do nothing */
    cout << x << endl;
    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. Get info from Computer clock.
    By Blizzarddog in forum C++ Programming
    Replies: 1
    Last Post: 02-07-2003, 09:03 AM
  2. world clock
    By nevermind in forum C++ Programming
    Replies: 1
    Last Post: 10-23-2002, 07:45 AM
  3. ANN: The Fourth Contest: Alarm Clock, sign up here
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 59
    Last Post: 08-10-2002, 12:24 AM
  4. Clock()
    By Paninaro in forum C Programming
    Replies: 4
    Last Post: 06-24-2002, 04:47 AM
  5. clock
    By meteor in forum Windows Programming
    Replies: 1
    Last Post: 02-17-2002, 02:38 AM

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