Well, if you just want some general feedback, I'll just point out a few things.
First of all, please use [
code] [/code] tags for your code (it's the <> symbol under the "Format:
I would use
(which are their C counterparts).
You also have a bunch of extraneous
s. While that won't have any sort of negative effect on your program, I would just keep it simple and only
what you really need.
I would also generally advice against using
and such. There's a nice article here explaining why: http://www.cplusplus.com/forum/articles/11153/
Instead of typing
while(answer=='n' || answer=='N')
, you can make it simpler by just typing
while (tolower(answer) == 'n')
(you'll need to
in order to use tolower
if(again=='y' || again=='Y')
if(again=='n' || again=='N')
can be simplified to just
if (tolower(again) == 'n')
since you don't need that
for the loop to run again.
Better yet, change the
loop to a
loop, like this:
// The game
} while (again == 'y');
Also, you don't need the
while(answer=='y' || answer=='Y')
cout<<"it took "<<tries<<" Tries to guess your number.\n\n";
If the player enters 'y' or 'Y', then the program will exit the
while (answer == 'n' || answer == 'N')
loop, so you know the answer has
to be yes, so you don't need to check that again (much less enter a "loop" and
out of it after the first iteration).
By the way, you should really check to make sure that the player actually enters either yes or no, and not something weird like "hi" or "nnnnnnnnnnnnnnn" (which will answer "no" 15 times in a row).
And why not have the computer guess smarter choices (i.e. guess 50 first, then 25 or 75 depending on the player's answer, and so on)?
You should probably also say in your program that you want the player's number to be between 0 and 99. If I'm thinking of 200 (thinking that the game just wants me to think of any whole number), the computer will never guess it correctly....