### Making a word guessing puzzle?

I am supposed to make a program that tells how many letters are in the word "hangman". And displays "You lose" after six wrong guesses and "You Win!" after guessing all the correct letters. This is what I have so far and I don't know where to go from here. I would be most appreciative if anyone could help.

#include <iostream>

using namespace std;

int main()
{ char letter;
try;
while (try <= 6)
cout << "Guess a letter" << endl;
cin >> letter;
if (letter == 'h' || letter == 'g' || letter == 'm'){
cout << "There is one." << endl;
}
else if (letter == 'a' || letter == 'n'){
cout << "There is two." << endl;
}
else {
try++
cout << "There are none." << endl;
}

}
`try` is a reserved keyword. Use a different name for your variable.
 ``123456789101112131415161718192021222324252627282930313233`` ``````#include using namespace std; int main() { char letter; int guessNumber = 0; while (guessNumber < 6) { cout << "You have " << 6-guessNumber << " guesses left.\n"; cout << "Guess a letter: "; cin >> letter; if (letter == 'h' || letter == 'g' || letter == 'm') { cout << "There is one." << endl; ++guessNumber; } else if (letter == 'a' || letter == 'n') { cout << "There is two." << endl; ++guessNumber; } else { ++guessNumber; cout << "There are none." << endl; } } }``````
I'm still wondering how to set it to say "You Win!" after guessing the letters h,a,n,g, and m. And "You Lose" after exceeding six guesses.
And also, the number of tries only diminishes when guessing correct letters.
Never mind, fixed the number of tries issue. Still trying to figure out the "you win" and "you lose".
 the number of tries only diminishes when guessing correct letters.

So if a user enters 'a' (there are two in the word), you lose a guess?
And if you enter 'x', you don't lose a guess?
In that case, you could have an unlimited amount of guesses if you keep guessing incorrectly.
Last edited on
Okay, I've figure out how to get the "You Lose!" to display. Still haven't figured out the "You Win!".
You could do this. Might not be the most efficient, but it works. I don't have the 'you lose' in this snippit.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667`` ``````#include using namespace std; int main() { char letter; int guessNumber = 0; bool h1 = false; bool g1 = false; bool m1 = false; bool a1 = false; bool n1 = false; while (guessNumber < 6) { if (h1 && g1 && m1 && a1 && n1) { cout << "You Win!"; return 0; } cout << "You have " << 6-guessNumber << " guesses left.\n"; cout << "Guess a letter: "; cin >> letter; if (letter == 'h') { cout << "There is one." << endl; h1 = true; } else if (letter == 'g') { cout << "There is one." << endl; g1 = true; } else if (letter == 'm') { cout << "There is one." << endl; m1 = true; } else if (letter == 'n') { cout << "There are two." << endl; n1 = true; } else if (letter == 'a') { cout << "There are two." << endl; a1 = true; } else { ++guessNumber; cout << "There are none." << endl; } } }``````
I tried adding that on to what I had and it worked. Thank You.
Topic archived. No new replies allowed.