# countdown timers

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

## 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 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 namespaceint 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,	cout<<j<<endl;	//Sleep for one second	Sleep(1000);	//and count down one.	--j; }//alert usercout<<"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 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.

• 9
• 10
• 12
• 10
• 10