Computer Science Canada Need help with strings! |
Author: | limpex [ Thu Dec 18, 2008 9:06 pm ] | ||||
Post subject: | Need help with strings! | ||||
Hey there guys. I need a help with this hangman program. This is what I need to do, you type in a secret word and print an "*" for the letters in word. Then you ask the user for a letter. If the letter is correct, it should replace in the "*"s. If the letter in incorrect, it shows 'invalid. Finally, I need to tell the guesses it took to guess the word. How do I replace the letter in the "*"? I am very new at strings and don't know much. Can any one fix my program? Thank You.
Mod Edit: Remember to use syntax tags! Thanks
|
Author: | TheGuardian001 [ Thu Dec 18, 2008 10:45 pm ] | ||||
Post subject: | Re: Need help with strings! | ||||
I'm assuming that what you want for the Asterisks is to make it so that the letters being typed can't be seen by other people, like in a password field. the first thing you will need to do this is:
this will set the output window to not print a character when a key is pressed (remember, you want to put this AFTER they enter option 1 or 2, otherwise they won't see what they have entered. you can cancel out the noecho statement with:
now that the program no longer outputs what the user enters, all you need to do is print out the "*" every time they press a button while entering the word (although if you do use this method, you will need to get the word one character at a time, instead of as a string) for guesses it took to take the word, simply use an integer variable. Start it at 0, and every time they guess a letter, increase it by one until they get the whole word |