Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

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

+3 votes
asked Nov 28, 2019 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


        cout << "Enter a guess: ";

        cin >> guess;


        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;


2 Answers

+1 vote
answered Dec 8, 2019 by Donzy Botwe (420 points)
Superb keep it up
0 votes
answered Apr 12, 2020 by Finlay Mitchell (240 points)
Only comment I can make is the "using namespace std;". Try to get out of that habit as it's classed as a bad habit. Instead, use std::cout, std::cin and so on.
commented May 7 by Henry Beuligmann (110 points)
using namespace std is better because it saves time and does the same thing as std::cout and things like that
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.