#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
srand(time(0));
int answer = rand() % 100 + 1;
// 循环猜数字
while (true) {
cout << "请输入你的猜测:";
int guess;
cin >> guess;
if (guess == answer) {
cout << "恭喜你猜对了!" << endl;
break;
} else {
cout << "很抱歉,你没有猜对。" << endl;
}
}
return 0;
}
小游戏代码
于 2024-04-15 17:26:37 首次发布