HI! :) I'm new to programming and I have a hangman assignment to do to learn the concept of functions. We aren't allowed to have cin or cout statements in the setupUnsolved or updateUnsolved functions.
I am having trouble getting the prevGuesses string to come out properly (this is supposed to print all the letters the user has guessed). Also, my updateUnsolved function doesn't "stay updated". So for phrase "hello" and first guess 'h' it would be h----, and second guess 'e', it would be -e---.
I am looking for suggestions on what I should do to fix the updateUnsolved function as well as printing all the guessed characters (the prevGuesses string)
On another question, how would I set up the "incorrect" guesses if the user guesses incorrectly so it deducts a try? (There are 7 guesses) I'm not looking for a direct answer, just more of the best loop to use or where to place this :)
Pass the unsolved string by reference. Right now you are creating a copy, updating and returning the copy, but never actually changing the original. If you pass by reference, you can change the original, so it keeps updating.
Where do you suggest I insert the "wrong guesses" part of the game? I currently have the following but it's not going as planned.. I tried printing wrongGuesses, but it comes out to 25 even after I initialized it to 0 so it's not taking in the number of wrong guesses correctly
** I replaced my for loop (from the top) to a while loop.
1 2 3 4 5 6 7 8 9 10 11 12 13
while (unsolved != phrase)
{
cout << "Enter a guess: "; //taking a guess
guess = getGuess(userGuess);
cout << endl;
for (int pos = 0; pos <= phrase.size()-1; pos++) // if the guess is not in the word
{
if (phrase.at(pos) != guess)
{
wrongGuesses++;
}
}
in your update function, if the loop doesn't find a match, return a null string. then check for the null string. if null string, increment the guess count.
My instructor had just told me we are not allowed to pass by reference so I would have to "update" my function in the main function.. how would I do this?