I am trying to create a guessing game. Everytime I execute, it only says the "couts." It lets me input numbers/letters, but, then it always says, "Would you like to play again? Type, 'G,' for, 'Go,' or, 'N,' for 'No.'" Please help me fix this.
If the number is only supposed to be from 1 to 100, the randomnumber assignment here needs to change - right now this is going to assign values from 3 to 1001.
int randomnumber = rand() % 999 + 3;
This block is getting run even if the correct number hasn't been guessed yet. So the "Awesome.." message gets printed out even if the wrong number is guessed and there are still tries left.
1 2 3 4 5 6 7 8 9
if(tries >= 20)
{
cout << "You ran out of tries!" << endl;
}
else
{
cout << "Awesome! You guessed the number!" << endl;
cout << "You got the right number in " << tries << " tries!" << endl;
}
computer number is 38 //I just added in output of the computer number so I knew what it was
Type in a number from 1 to 100. You have 20 tries left.
15
The number you guessed was too low! Try again!
Awesome! You guessed the number!
You got the right number in 2 tries!
Would you like to play again? Type, 'G,' for, 'Go,' or, 'N,' for 'No.'
n
See you later!
I might try breaking the code into separate functions though I'm not sure if the assignment allows you to do that.