Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Newbie

Name: Anonymous 2009-08-12 20:43

http://pastebin.com/m4319da6a
Basic hangman game, I got it from Beginning C++ Through Game Programming. I was doing one of the exercises at the end of a chapter and it said to take the original hangman game and make a function for getting the player's guess and make a function for checking if the letter is in the secret word. I'm not sure what the problem is, the code compiles fine. I wasn't sure where to create the variables at because leaving them where they were in main wasn't working because the function that uses them is declared before main. Any help would be appreciated, sorry for the WALL OF TEXT

Name: !3LrT5NRVks 2009-08-12 21:04

const string THE_WORD = words[0];            // word to guess

string soFar(THE_WORD.size(), '-');

You are trying to access words[0] before you push the words on to the the vector in main.  I'm surprised this compiles.  Just toss the const, leave the declaration for THE_WORD and soFar there, and do your actual initializing of those variables in the main.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List