### Simple hangman game

Greetings to everyone!
Firstly, I must apolagize for my English, I'm learning.
What I have to do is the hangman game the simplest way as possible.
This is the code I have at the moment:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657`` ``````#include using namespace std; int main() { char a,intro; char word[]={}; char sol[]={}; int i,j,attempts=0; cout<<"Introduce a sentence:"<>attempts; for(i=0;i<25;i++) cout<>a; } ``````

But it doesn't work correctly, so my doubt is: how could I do it so that the number of attempts subtracts one number when I fail a letter and the game ends when you run out of attempts?
(I don't know if I've explained well, any question ask me)

Important: I have to complete the exercise just with the structure it appears in the code I've done, only with the library <iostream>.

¿Could you help me? Thank you so much!
Well, there's lots to work on here. First of all `word` and `sol` are initialized to empty arrays, but you populate more members than they contain in lines 11 and 27. For a beginner project like this, why don't you assume a maximum word length like 80 characters or something. You would then change lines 6 and 7 to something like:

 ``12`` ``````char word[80]=""; char sol[80]="";``````

There are more elegant ways to do this, but that will work for now.

You are obviously working on loops. So figure out what needs to be in your loop and what the condition(s) is/are that will break you out of the loop.

Off the top of my head, I think the loop should contain:
- Printout of the guessed letters so far
- Statement of how many guesses (actually, incorrect guesses) remain
- Prompt for a letter
- Refresh screen
- Statement indicating if last guess was correct

You will leave the loop if
- You guessed the entire word
- You run out of guesses

You have a lot of those elements in your code, but there is no outer loop to contain them all.
Topic archived. No new replies allowed.