Nov 24, 2012 at 3:15am UTC
instead of using the correct bool variable, you could break out of the for loop when the right number is guessed. You use a return statement, so the correct variable isn't really used.
At the moment you get the "Sorry you lost " message regardless.
The "Sorry you lost " message could be another else if condition.
Nov 24, 2012 at 3:23am UTC
so that else if statement be this?
2 else if (number != guess && numGuesses = 5)
cout<< "Sorry,you lost.The number is:"<< number <<endl;
Last edited on
Nov 24, 2012 at 3:26am UTC
Nov 24, 2012 at 3:25am UTC
Looks alright to me - give it a try.
Hope all goes well.
Nov 24, 2012 at 3:59am UTC
Sorry, wasn't thinking straight - numGuesses only makes it to 5 after the for loop, so you need to compare to 4. Good to see you changed the assignment operator to an equality operator.
This should be sufficient:
else if (numGuesses== 4)
I would prefer a comparison to test for a win rather than leave it for an else clause. The else can be for any other error - not that there should be any of those.
Also get rid of references to the correct variable on lines 12, 19 & 46.
And no need for the break before the return (have one or the other). If you want to have more code after the end of the for loop, then use the break.
See how you go.
Nov 24, 2012 at 4:08am UTC
I dont understand why i need to change those lines that you say.What variable?