Thread: Setting a countdown timer in C++?

  1. #1
    Registered User
    Join Date
    May 2020
    Posts
    1

    Setting a countdown timer in C++?

    Hi everyone!
    So, I'm trying to set a countdown timer with this code but everytime I run it I have to set the amount of seconds the countdown is going to go for. Instead of that I wanted to set the amount beforehand so when I run it the countdown would start automatically. Is there a way I can do that with this code?
    Code:
    #include <unistd.h>
    #include <iostream>
    #include <stdio.h>
    #include <stdlib.h>
    
    
    using namespace std;
    
    
    
    
    int main()
    {
         int iCounter;
    
    
        scanf ("%d", &iCounter);
    
    
        while (iCounter !=0){
            printf ("\n\t%d", iCounter);
            iCounter --;
            sleep (1);
            system ("cls");
        } printf("\nCount down timer has expired\n");
    
    
        return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,063
    Like this?
    Accessing command line parameters/arguments - Cprogramming.com

    > Setting a countdown timer in C++?
    None of your actual code is C++ code at all.
    It's all 'C' code.
    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. problem with countdown timer
    By Moon River in forum C Programming
    Replies: 2
    Last Post: 09-10-2014, 11:32 AM
  2. want to add countdown timer to my program
    By megazero1316 in forum C Programming
    Replies: 1
    Last Post: 12-14-2013, 01:00 PM
  3. Countdown timer question:
    By Vadurr in forum C Programming
    Replies: 3
    Last Post: 11-22-2010, 08:13 AM
  4. Countdown timer
    By george7378 in forum C++ Programming
    Replies: 1
    Last Post: 06-24-2010, 05:29 AM
  5. Replies: 4
    Last Post: 08-13-2003, 07:25 PM

Tags for this Thread