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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
using namespace std;
int main()
{
char a,intro;
char word[]={};
char sol[]={};
int i,j,attempts=0;

cout<<"Introduce a sentence:"<<endl;
gets(word);
cout<<"Introduce the attempts number"<<endl;
cin>>attempts;
for(i=0;i<25;i++)
  cout<<endl;


i=0;
while(word[i]!='\0')
i++;

cout<<"You have "<<attempts<<" attempts"<<endl;

cout<<"You have "<<i<<" letters"<<endl;
for(j=0;j<i;j++)
{
  sol[j]='*';
  cout<<"*";
}
cout<<endl;
sol[j]='\0';

a=getchar();


cout<<"Introduce a letter: ";
a=getchar();


intro=getchar();
for(j=0;j<i;j++)
  if(palabra[j]==a)
   sol[j]=a;

cout<<endl;
for(j=0;j<i;j++)
 cout<<sol[j];
cout<<endl;






cin>>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!
Up! Help please!
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:

1
2
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.