Hi!
This is what i want to do:
- Create a countdown
- When the countdown reaches 0, something should happen
So, the actual problem is how to create a countdown.
I really appreciate help!
Hi!
This is what i want to do:
- Create a countdown
- When the countdown reaches 0, something should happen
So, the actual problem is how to create a countdown.
I really appreciate help!
Include <ctime>.
Set the start time like:
Then check if the time limit is passed (in a loop of course):Code:unsigned int stime=clock();
Code:if(clock() > stime+time_limit)
thats a polling method with all the polling disadvantages.
according to your os you can also use a system timer to call back a function after a time duration.
real time clock (rtc) on linux or
windows multimedia timer on ... you guess it ... windows does the job
Check the FAQ
Don't quote me on that... ...seriously
No, you've all misunderstand me. I mean like the countdown starts at 20 seconds then goes to 0. It has nothing to do with the actual clock.
Like that?Code:void count_down(unsigned secs) { for (unsigned i = secs; i; --i) { std::cout << i << '\n'; Sleep(1000); } }
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
You obviously haven't explored what the clock function does. It DOES NOT return the current time. It returns the number of *milliseconds since your program has started. It's heavily relied upon by programs that require timing.
* this is actually designated by CLOCKS_PER_SEC which is commonly 1000
Don't quote me on that... ...seriously
dont think so.
thats exactly what the wmm-timer can provide. but high resolution/accuracy and without polling your cpu to death
http://msdn2.microsoft.com/en-us/library/ms712704.aspx
http://msdn2.microsoft.com/en-us/library/ms712713.aspx