simple C++ game code

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

using namespace std;

// Function to generate a random number within a specified range
int generateRandomNumber(int min, int max) {
    return rand() % (max - min + 1) + min;
}

int main() {
    // Seed the random number generator with the current time
    srand(time(0));

    // Generate a random number between 1 and 100
    int secretNumber = generateRandomNumber(1, 100);

    // Initialize variables
    int guess;
    int attempts = 0;

    // Game loop
    do {
        // Get user input
        cout << "Enter your guess (1-100): ";
        cin >> guess;

        // Increment the attempts counter
        attempts++;

        // Check if the guess is correct, too high, or too low
        if (guess == secretNumber) {
            cout << "Congratulations! You guessed the number in " << attempts << " attempts." << endl;
        } else if (guess < secretNumber) {
            cout << "Too low. Try again." << endl;
        } else {
            cout << "Too high. Try again." << endl;
        }

    } while (guess != secretNumber);

    return 0;
}