If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Hangman

I am having trouble with a hangman program. Every time I try to compile, it tells me that variables haven't been declared in functions. Below is the code; I need help with the "evaluate" function specifically. That's where the variables are showing as undeclared. How do you use values from main() in other functions?

Re: Hangman

Thanks for the help, I can get it to compile now. Now, there's another problem. The program can detect whether the guess is incorrect or not, but it doesn't update: what letters you've used(it just stays blank), soFar to include the characters to fill in the blanks, and how many incorrect guesses you have left. It just keeps on saying I have 8 guesses left. Whether a get a million wrong or not. Also, you can never win. It just keeps on telling you "Yes, " << guess << " is in the word! ", but it never lets you complete the game.

Re: Hangman

You're modifying the variables "soFar" and "wrong" in the evaluate function, but since you have passed them "by value" to the function, you're just modifying a copy of the variables, and it doesn't affect the ones declared in main().

Re: Hangman

Originally Posted by ZainAsad

The book I'm using is C++ Through Game Programming: Second Edition.

I'm not familiar with that book, so I may be too quick to judge. However, looking at the table of contents I can see why you are running into these problems: the book seems to explain the STL (in one chapter!) before it explains functions, references and classes. Again, I don't have the book so I may be off here, but that doesn't seem logical to me.

If you'd like to use a second book as a reference, have a look here. Bjarne Stroustrup's book covers everything quite detailed. Accelerated C++ is a good beginners book if you want to do real programming from the outset. I'm not familiar with other beginners books.

Cheers, D Drmmr

Please put [code][/code] tags around your code to preserve indentation and make it more readable.

As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Re: Hangman

@GameZelda: Thank you for the assistance. I could also set new variables, and then make those variables the return values of the functions. In turn, those return values could be the modified values "soFar" and "wrong", couldn't they? At least, that's what I understand from the book.
@D_Drmmr: Are you referring to the book Principles and Practice Using C++? I think it would be beneficial to have a book written by the actual creator of C++! As he would know the innards of it.