I'm still stuck on my number guessing game. (The program guesses the number the user inputs)I have wokred out some kinks but i am stuck again. I have a bunch of stuff but i am focused right now on getting the program past asking if the first guess of 50 is correct.

What happens is it puts out the correct statments but when i ask if the user would like to re-use the game, it will work if they say yes but it just dosent do anything if they say no. I have no errors or warnings.

Any other feedback on my code to help me would be appeciated but i can't figure out how to make it work right.

My Code:

// Project 8.4. Guesses the number the user enters between 1-100.

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

using namespace std;

int UsersNum, YesNo, HighLow, GuessedNum, Re_Use;


int main ()
{
    srand(time(NULL));
do
{
    cout << "Welcome to the number guessing game! \n"; 
    cout << "I will try and guess the number you will enter. \n";
    cout << "Please enter a number between 1 - 100. \n";
    cin >> UsersNum;

    cout << "Is your number 50? Enter 1 for Yes or enter 2 for No. \n";
    cin >> YesNo;

        if (YesNo == 1) 
        cout << "I guessed your number!Would you like to play again? Enter 1 for yes or 2 for no.\n";
        cin >> Re_Use;
        system ("CLS");
}
while (Re_Use != 2);

do
{       
            if (YesNo == 2)
                cout << "Is it too high or too low? \n";
                cout << "Enter 1 for too high or enter 2 for too low. \n";
                cin >> HighLow;

    switch (HighLow)
    {
        case 1:   
            cout <<  rand() % 50 + 1; 

            cout << " Is this your number? \n";
            cin >>GuessedNum;
        break;

        case 2:
            cout <<  rand() %  + 1; // (edit this so it guesses higher number)
            cout << "Is this your number? Enter 1 for yes or enter 2 for no. \n";
            cin >> GuessedNum;
        break;

        default:
            cout << "Something was entered wrong. \n";
        break;
    }

        if (GuessedNum == 1)
            cout << "I have guessed your number correctly! \n";
            cout << "Would you like to play gain? Enter 1 for yes or enter 2 for no. \n";
            cin >> Re_Use;
}   
while (Re_Use != 1);

return 0;
}

When I assign the value 2 to Re_Use then your while loop doesnot get executed.You should put switch before your second input in a while loop.

.... I don't know how to do that... Can you either explain it to me or find a website where i can learn it? I would look for a website but i don't know what im looking for :/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.