Sign in to follow this  

countdown timers

This topic is 4254 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

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,
cout<<j<<endl;


//Sleep for one second
Sleep(1000);

//and count down one.
--j;
}


//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

This topic is 4254 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.

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