#include <iostream>
#include <cstdlib> // For rand() and srand()
#include <ctime> // For time()
using namespace std;
int main() {
// 初始化随机数生成器
srand(static_cast<unsigned int>(time(0)));
int number = rand() % 100 + 1; // 生成1到100之间的随机数
int guess;
bool won = false;
cout << "欢迎来到猜数字游戏!我已经想好了一个1到100之间的数字。" << endl;
for (int i = 1; i <= 7; ++i) { // 给玩家7次机会
cout << "第 " << i << " 次猜测:" << endl;
cin >> guess;
if (guess == number) {
won = true;
break;
} else if (guess < number) {
cout << "太小了!再试一次吧!" << endl;
} else {
cout << "太大了!再试一次吧!" << endl;
}
}
if (won)
cout << "恭喜你,猜对了!答案确实是 " << number << "。" << endl;
else
cout << "很遗憾,次数用完了。正确答案是 " << number << "。" << endl;
return 0;
}