Sign in to follow this  

countdown timers

Recommended Posts

Hi, I would like to create a small program that displays and counts down the time in seconds. How would I go about doing this in the win32 console using C?

Share this post

Link to post
Share on other sites
Take a look at this, And this.

Do you want to make a kind of 'egg timer', that counts down in seconds? if so, the above links are overkill, and you would be better off using 'sleep()'.

Sleep is included in windows.h, so you will need to include that. Basically, it just takes the time in milliseconds, and the program will 'pause' for that amount of time. Heres an example:

#include<iostream> //include input/output
#include<windows.h> //include windows.h so we can use "Sleep"

using namespace::std; //set it so we are using the std namespace

int main()

int CountTime = 0; //local varialbe so we can hold the count time

cout<<"How long would you like to countdown?"<<endl; //prompt the user
cin>>CountTime;//get the user input, which is the time to count down

//count down from 'CountTime'
for(int j = CountTime; j != 0;)
//print the current value,

//Sleep for one second

//and count down one.

//alert user
cout<<"Time's up!"<<endl;

//exit the program.
return 0;

But if I missed the mark slightly, you should be able to fiddle with the code above to get what you want.

[Edited by - Liam M on April 17, 2006 11:36:04 PM]

Share this post

Link to post
Share on other sites
Yeah I am just trying to make an egg timer. The code you've posted does the trick however I would like the text to be displayed in same place instead of being printed on a new line each second.

Thanks for the help and links.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this