Programming: Countdown Timer

Source: Internet
Author: User

#include <iostream>#include<Windows.h>using namespacestd;classti{intH//hours    intM//minutes    intS//seconds Public:    void Set(intHourintMinintSec//Passing timer values{h=hour; M=min; S=sec;    }; voidTick ()//Timing Bounce{Sleep ( +);//execution hangs for 1000 milliseconds, that is, wait one second before proceedings--; if(S <0) {s= -; M--; if(M <0) {m= -; H--;    }        }    }; voidShow ()//Show remaining time    {        if(H <Ten) {cout<<0; } cout<< h<<":"; if(M <Ten) cout<<0; cout<< m<<":"; if(S <Ten) cout<<0; cout<<s;    }; voidrun () { while(H | | m | | s)//keep running until full 0{tick (); System ("CLS");                    Show (); } cout<<"Time out!"<<Endl; }}; intMain () {TI t; T.Set(0,2,0);//2 minutes Countdown .T.run ();}

Wait a second method,

(1) Sleep (1000); wait 1000 milliseconds

(2) #include <time.h>

time_t t=time (NULL); Gets the number of seconds that have been counted since January 1, 1970

while (Time (NULL) ==t); Until the number of seconds is different, that's 1 seconds.

Programming: Countdown Timer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.