Number guessing game

I am trying to make a number guessing game, which tells the user whether their number is too high or too low. It works for the first guess, but keeps repeating "guess again". I am so lost
Last edited on
You're using your function incorrectly. The contract your function secretNumberGenerator offers is: "Give me a number, and I'll give you a random number that's bigger than zero, and less than or equal to what you gave me." (Actually, what if you give it something less than zero for max_Guess? Maybe you should have an unsigned parameter...)
This means lines 15-20 should look something like this:
1
2
3
4
5
	int max_Guess;  //declare a variable to hold the user's input
	cout << "\n\n Please enter maximum guess: ";  //print a prompt
	cin >> max_Guess;  //get a number from the user
	int randomSecret = secretNumberGenerator(max_Guess);  //use function to initialize secret value
	int guess = 0;
Last edited on
Thanks that helped. But how would i allow the user to guess again? At line 33 I know I went wrong. First of all, if it worked, wouldn't it restart the whole secretNumberGame function? I just want it to ask them to input another guess (if y is selected)
Last edited on
^ How would I get guessAgain to only loop back to the actual guess?
Just a few adjustments to make
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int guess (){
    bool run = true;
    char ques = 'y';
    while(run) {
          secretNumberGame();
         // run = secretNumberGame();  secretNumberGame() does not return bool.
        
        if (run) {   //dont need this. while(run) takes care of it
            cout << "\nGuess again? (y/n) ";
            cin >> ques;
            if (ques == 'y' || ques == 'Y') run = true;
           /* else if (ques == 'n' || ques == 'N') run = false;
            else run = false;*/
           else run = false;
         //}
     }
     return 0;
}
How would I get guessAgain to only loop back to the actual guess


what do you mean by loop back and actual guess ?
I mean that it should prompt them to enter another guess. So instead of infinitely asking them to guess again (y/n)? it should actually say "enter your guess" I don't know how to get it back to that point
So instead of infinitely asking them to guess again (y/n)? it should actually say "enter your guess"


Are you instead saying you want the program to infinitely say "Enter you guess"?
If you dont want guess again (y/n)? but Enter guess , how do you intend your program to end?
Topic archived. No new replies allowed.