Basic Number Guessing Game In C++ using VISUAL STUDIO.

                                                   Author : United Vibes ( Maruf Anwar)


Click Here to Subscribe to My Channel.

                                                     BASIC NUMBER GUESSING
                                                                         GAME



                                                                                         SOURCE CODE :

// #include<bits/stdc++.h>

#include<iostream>

#include<string>

#include<array>

#include<ctime>

using namespace std;

int main()

{

    int count = 1;

    cout << "\t\t\t\t\tBasic Number Guessing Game" << endl;

    srand(time(0));

    int NumbertoGuess = rand() % 1000;

    int userguess;


    bool continuePlaying = true;

    while (continuePlaying == true)

    {



        cout << "\tEnter A Number Between 0 and 999" << endl;

        cin >> userguess;


        if (NumbertoGuess == userguess)

        {

            cout << " Congratulations! You Won as " << NumbertoGuess << " Was my Number!" << endl;

            cout << "It Took You " << count << " Tries To Get The Answer!" << endl;


            cout << "Do You want to Play Again (Y/N)?" << endl;


            string playagain;

            cin >> playagain;

            if (playagain == "y" || playagain == "Y")

            {

                NumbertoGuess = rand() % 1000;

            }

            else if (playagain == "n" || playagain == "N")

            {

                continuePlaying = false;

            }

        }


        else if (NumbertoGuess > userguess)

        {

            cout << "My Number Is Greater Than " << userguess << "\n please try AGAIN!" << endl;

            count++;

        }

        else if (NumbertoGuess < userguess)

        {

            cout << "My Number Is Lower Than " << userguess << "\n Please Try AGAIN!" << endl;

            count++;

        }

    }

    return 0;

}

          

                                                              OUTPUT : 



 

Subscribe To My Channel for projects like THIS.

Comments

Popular posts from this blog

Simple Calculator in C