#include <iostream>
#include <cstdlib>
#include <ctime>
int main() {
srand(time(nullptr));
int target = rand() % 100 + 1;
int guess = 0;
int attempts = 0;
std::cout << "欢迎来到猜数字小游戏!\n";
std::cout << "我已经选择了一个1到100之间的数字,你猜猜是多少?\n";
while (guess != target) {
std::cout << "请输入你的猜测:";
std::cin >> guess;
++attempts;
if (guess < target) {
std::cout << "太小了,再试一次!\n";
} else if (guess > target) {
std::cout << "太大了,再试一次!\n";
} else {
std::cout << "恭喜你,猜对了!你用了" << attempts << "次猜对了哦!\n";
}
}
return 0;
}
动动手指,点个赞吧。