#include <iostream>
#include <cstdlib> 
#include <ctime>   
using namespace std;

int main() {
    srand(static_cast<unsigned int>(time(0)));

    int numero_secreto = rand() % 100 + 1;

    int intento;
    bool adivinado = false;

    cout << "¡Bienvenido al juego de adivinanza!" << endl;
    cout << "Adivina el número secreto entre 1 y 100." << endl;

    while (!adivinado) {
        cout << "Ingresa tu intento: ";
        cin >> intento;

        if (intento < 1 || intento > 100) {
            cout << "Por favor, ingresa un número entre 1 y 100." << endl;
        } else if (intento < numero_secreto) {
            cout << "El número secreto es mayor. Intenta de nuevo." << endl;
        } else if (intento > numero_secreto) {
            cout << "El número secreto es menor. Intenta de nuevo." << endl;
        } else {
            cout << "¡Felicidades! Has adivinado el número secreto." << endl;
            adivinado = true; // Terminar el bucle
        }
    }

    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: