12345678910111213141516171819202122232425262728293031323334353637
#define _WIN32_WINNT 0x0501 #include <windows.h> #include <iostream> using namespace std; int main () { int actionType; int seconds; cout << "What would you like to do?" << endl; cout << "1 = shutdown; 2 = hibernate" << endl; cin >> actionType; if (actionType != 1 || actionType != 2) { cout << "Invalid action ID" << endl; cout << "Please retype action ID" << endl; cin >> actionType; } cout << "Seconds until action: "; cin >> seconds; if ((MessageBox(NULL, "Are you sure?", "Confirm", MB_OKCANCEL)) == MB_OK) { HWND hWnd = GetConsoleWindow(); ShowWindow(hWnd, SW_HIDE); Sleep(seconds * 1000); if (actionType == 1) { system("shutdown -s -f -t 10"); } else if (actionType == 2) { system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0"); } } return 0; }
12345678
if (actionType == 1) { system("shutdown -s -f -t 10"); } else if (actionType == 2) { system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0"); }
if (actionType != 1 || actionType != 2)
if (actionType != 1 && actionType != 2)