Page 1 of 1

Time-Shutdown Program

Posted: Fri May 07, 2010 2:22 am
by wrighty1986
basically just asks you in how many hours, minutes and seconds your computer is supposed to shut down. After declaring the time, a messagebox comes up and asks you to confirm what you have declared.
Code: Select all
#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
    beginning:;
    cout << "Enter time to shutdown"<< endl << "h/min/sec(enter with spaces): ";
    int x;
    cin >> x;
    int y;
    cin >> y;
    int z;
    cin >> z;
    
    
    char text[255];
    sprintf(text, "Shutdown in %d hours, %d minutes and %d seconds. Please confirm.",x, y, z);
    int msg;
    msg=MessageBox(NULL, text, "Confirmation", MB_OKCANCEL);
    switch(msg)
    {
        case IDOK:
             goto timer;
             break;
        case IDCANCEL:
             cout << "Shutdown has been cancelled." << endl;
             cout << endl;
             goto beginning;
             break;
    }
    
    
    timer:;
    Sleep(x*3600000 + y*60000 + z*1000);
    
    system("shutdown -s -t 0");
    return 0;
}