Thread: counting seconds

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    104

    counting seconds

    How do I make my program to count secods... something like a timeout?
    12 11 10 9 8 7 6 5 4 3 2 1 ... and then something happens..

    But how do I make it to show the numbers ?

    Thank you in advance!
    Ilia Yordanov,
    http://www.cpp-home.com ; C++ Resources

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Code:
    #include <iostream>
    int main ( ) {
        for ( int i = 10 ; i >= 0 ; i-- ) {
            cout << i << " " << flush;
            sleep( 1 );
        }
        return 0;
    }
    The sleep function is whatever your compiler / OS combination allows for sleeping for a second.

    I believe the FAQ has some ideas
    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.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    104
    It ain't work... "sleep" undeclared identifer
    Ilia Yordanov,
    http://www.cpp-home.com ; C++ Resources

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    As Salem said...

    >>>
    The sleep function is whatever your compiler / OS combination allows for sleeping for a second.´
    <<<

    ... this does tend to be compiler/OS specific. To acheive this with VC++ for example you would use Sleep(1000); with a capital S and in milliseconds. I think Borland use wait().
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. counting seconds
    By goran00 in forum C Programming
    Replies: 4
    Last Post: 01-21-2008, 02:24 PM
  2. How to build a timer that counts the seconds elapsed?
    By Nazgulled in forum C Programming
    Replies: 17
    Last Post: 05-28-2007, 12:26 PM
  3. Timing C program always returns 0 seconds.
    By hamsteroid in forum C Programming
    Replies: 6
    Last Post: 03-24-2007, 10:02 AM
  4. Problem with simple case statements
    By shoobsie in forum C Programming
    Replies: 2
    Last Post: 05-08-2006, 08:39 AM
  5. Time to seconds program
    By Sure in forum C Programming
    Replies: 1
    Last Post: 06-13-2005, 08:08 PM