Thread: clock problems

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

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

    #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;
      if(clock() == 5000)
          cout << x << endl;
      return 0;
    Any thoughts?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Perhaps you want something like
    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.

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, 10: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
    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, 03:38 AM