让我看看我的评论区有什么发言。

测试代码

#include <iostream>
#include <cstdlib>
#include <ctime>

int main() {
    // 初始化随机数种子
    std::srand(static_cast<unsigned int>(std::time(nullptr)));

    // 生成一个 1 到 100 之间的随机数
    int target = std::rand() % 100 + 1;
    int guess = 0;
    int attempts = 0;

    std::cout << "Welcome to the Number Guessing Game!" << std::endl;
    std::cout << "I'm thinking of a number between 1 and 100." << std::endl;

    // 游戏循环,直到用户猜中为止
    while (guess != target) {
        std::cout << "Enter your guess: ";
        std::cin >> guess;
        attempts++;

        if (guess > target) {
            std::cout << "Too high! Try again." << std::endl;
        } else if (guess < target) {
            std::cout << "Too low! Try again." << std::endl;
        } else {
            std::cout << "Congratulations! You guessed the number in " << attempts << " attempts." << std::endl;
        }
    }

    return 0;
}