is this a good beginner game made by me? (cpp)

0 votes
asked Nov 28 by anonymous

#include <iostream>

#include <cstdlib>

#include <ctime>

using namespace std;

int main()

{

    //seed random number generator

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

    //max possible secret number

    const int MAX_NUMBER = 100;

    //random number between 1-100

    int secretNumber = (rand() % MAX_NUMBER) + 1;

    //welcomes player and creates two variables

    int tries = 0;  //number of times player has guessed

    int guess;      //player's current guess

    cout << "\tWelcome to Guess My Number" << endl << endl;

    cout << "Guess my secret number between 1 and ";

    cout << MAX_NUMBER << "." << endl << endl;

    //guessing loop

    do{

        cout << "Enter a guess: ";

        cin >> guess;

        ++tries;

        if (guess > secretNumber)

        {

            cout << "Too high!" << endl << endl;

        }

        if (guess < secretNumber)

        {

            cout << "Too low!" << endl << endl;

        }

    } while (guess != secretNumber);

    cout << endl;

    cout << "You win! You got it in " << tries << " tries!";

    cout << endl;

    return 0;

}

1 Answer

0 votes
answered Dec 8 by (400 points)
Superb keep it up
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...