如果你们搜索的关键字是游戏,那很好,你选中我了,点个关注,我让你玩上瘾! 现在麻烦你把下列代码复制! 温馨提示:一旦猜中立马关机,所以请各位小心为上!
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <windows.h> // 用于关机命令
using namespace std;
int main() {
srand(time(0));
int bomb = rand() % 100 + 1; // 1-100随机炸弹数字
int guess;
cout << "=== 数字炸弹游戏 ===" << endl;
cout << "猜一个1-100的数字,猜中就关机!" << endl;
while (true) {
cout << "你的猜测: ";
cin >> guess;
if (guess == bomb) {
cout << "轰!你猜中了!电脑将在10秒后关机..." << endl;
system("shutdown -s -t 10"); // Windows关机命令(10秒后)
cout << "输入 shutdown /a 可以取消关机" << endl;
break;
}
else if (guess < bomb) {
cout << "炸弹比 " << guess << " 大" << endl;
}
else {
cout << "炸弹比 " << guess << " 小" << endl;
}
}
return 0;
}