counting seconds

This is a discussion on counting seconds within the C++ Programming forums, part of the General Programming Boards category; How do I make my program to count secods... something like a timeout? 12 11 10 9 8 7 6 ...

  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
    32,822
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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,831
    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, 01:26 PM
  3. Timing C program always returns 0 seconds.
    By hamsteroid in forum C Programming
    Replies: 6
    Last Post: 03-24-2007, 11:02 AM
  4. Problem with simple case statements
    By shoobsie in forum C Programming
    Replies: 2
    Last Post: 05-08-2006, 09:39 AM
  5. Time to seconds program
    By Sure in forum C Programming
    Replies: 1
    Last Post: 06-13-2005, 09:08 PM

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