实现一个简单的关机程序,可以选择是否关机以及设置关机的时间。
#include<windows.h>
#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;
int main() {
int h, m, s;
char c;
cout << "\n\n\n -------------------------------------------------------\n";
cout << " | 是否关机?(Y/N): |\n";
cout << " -------------------------------------------------------\n";
cout << " 请输入:";
c = getchar();
if (c == 'Y' || c == 'y') {
system("cls");
cout << "\n\n\n -------------------------------------------------------\n";
cout << " | 请输入多少时间后关机:(小时/分钟/秒) |\n";
cout << " -------------------------------------------------------\n";
cout << " 请输入:";
cin >> h >> m >> s;
system("cls");
while (h || m || s) {
cout << "\n\n\n -------------------------------------------------------\n";
cout << " | 距关机还有: |\n";
cout << " -------------------------------------------------------\n";
cout << " " << h << "小时 " << m << "分钟 " << s << "秒" << endl;
Sleep(1000);
system("cls");
if (s) --s;
else if (!s && m) {
s = 60;
--m;
} else if (!s && !m && h) {
m = 60;
s = 60;
--h;
}
}
system("shutdown -s -f -t 0");
}
return 0;
}