Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> //as usual basic i/o objects
- #include <chrono> //for C++11 time like the seconds() line 32
- #include <ctime> //C time functions--useful
- #include <thread> //for the sleep function line 32
- using namespace std;
- using namespace std::chrono; //the C++11 time library namespace
- int main() {
- time_t st=time(nullptr); //set programme startup time
- tm* startTime{localtime(&st)}; //setup a tm structure(for time information based on st(ie: startup time))
- tm timeObj;
- unsigned hr=0,min=0;
- cout<<"Enter prescribed hour(24hr clock): ";
- cin>>hr; //user enters hour 0 - 23
- cout<<"\nEnter prescribed minute: ";
- cin>>min; //user enters minute 0 - 60
- if((hr>=0)&&(hr<=23)&&(min>=0)&&(min<=60)) { //check
- timeObj=*startTime; //assign timeObj the startup time
- timeObj.tm_hour=hr; //set the hour aspect of the startup time to the user defined one
- timeObj.tm_min=min; //set the minute aspect of the startup time to the user defined one
- //time difference in seconds between user defined time and startup time
- double timeDiff=difftime(mktime(&timeObj),st);
- if(timeDiff<0.0) {
- cout<<"Time passed!!!"; //tell the user to be careful
- }
- else {
- this_thread::sleep_for(seconds((int)timeDiff)); //wait for truncated-to-int "time difference" seconds
- //this ensures(not effectively) the user is informed on the time
- //the drug must be taken
- cout<<"\a\a\a\a\a\n\nHey!!! Take your drugs NOW!!!\a\a\a\a\a"; //inform
- }
- }
- delete startTime; //clear stuff
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement