Jump to content
  • Advertisement
Sign in to follow this  

countdown timers

This topic is 4478 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!