hangman game help !

guys i have made a hangman game and its working well!
the problem is that when i repeat a letter that is already guessed, it will decrement my guesses left.
P.S : don 't look at the comments its not english (i am lebanese).

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>/**for cout, cin...*/
#include <string>/**string **/
#include <cstdlib>/**random number generating**/
#include <vector>/**to use vectors**/
#include <algorithm>/**to find letter and arrange them**/
#include <ctime>/**aso for random number**/
#include<windows.h>/**system("....")**/
#include <cctype>/**to convert to uppercase letter**/

void hangmanboard(void);
void hangmanboard2(void);

using namespace std;

int main (void)
{
    system ("color 1a");
    const int MAX_WRONG = 8;
    vector<string>words;

words.push_back ("GUESS");
words.push_back ("HANGMAN");
words.push_back ("DIFFICULT");
words.push_back ("PROGRAMMING");

srand (static_cast <unsigned int> (time(NULL)));/**seed the generator**/
random_shuffle (words.begin() , words.end());/**bi 5alle y5arbet l aseme**/
const string THE_WORD = words[0];/**bi na2e awal ra2em. w kel marra awal ra2em byer8ayyar**/
int wrong = 0;/**kam marra 8allat**/
string soFar(THE_WORD.size() , '-');/**bi 5ale l a7rof ysiro -**/

string used = "";/**chou henne l a7rof li sta3malon**/

cout<<"welcome to hangman ! "
    <<"good luck"<<endl;

/**main loop **/
while ((wrong<MAX_WRONG) && (soFar != THE_WORD))/**hayde kermel t3id l loop ta ken 7ezer am 5eser**/
{
    cout<<"you have "<<(MAX_WRONG-wrong)<<" incorrect guesses left"<<endl;/**addeh 3endo tries**/
    cout<<"you have used the following letters : \n \n "
        <<used<<endl
        <<"so far, the word is "<<soFar<<endl;


char guess;/**declaring l variable yalli ra7 yna2ia le3eb**/
cout<<"enter your guess :"<<endl;
cin>>guess;
guess = toupper(guess);/**bi 7ett enno l guess hiyye mettel el GUESS (uppercase)**/

used += guess;/**bi 7ett l gess ma3 l guesse yalli na2ehon l user  **/

if (THE_WORD.find(guess) != string::npos)/** bi nabbech 3al guess bel word wel !=  string::npos houwe metel != did not find**/
{
    cout<<"that 's right ! "<<guess
        <<"is in the word !"<<endl;

    /**update so far to include
    newly guessed letter**/

for (int i=0 ; i<THE_WORD.length() ; ++i)/**bya3mel update lal game w bi 7ett l guess ma7all l letter l le2eh**/
{

    system ("cls");
    if (THE_WORD[i] == guess)/**iza le2a ci letter metel l guess...**/
    {
        soFar[i] = guess;/**bi 7ett ma7al l -, l guess**/
    }

  }
}
else
{
    cout<<"sorry, "<<guess<<" is not in the word"<<endl;
    ++wrong;/**bi zid l wrong number of guesses**/
    system ("cls");
}
}
/**SHUT DOWN**/

if (wrong == MAX_WRONG)/**iza 5allas l tries**/
{
    system ("color 40");
    cout<<"\n you 've been hanged \n \n \n";
    hangmanboard();
}
else
{
    system("color 1a");
    cout<<"you guessed it"<<endl;
    hangmanboard2();
}
cout<<"the word was: "<<THE_WORD<<endl;


return 0;
}
void hangmanboard()
{
    cout<<"+--------+  "  <<endl;
    cout<<"|        |  "  <<endl;
    cout<<"|        0  "  <<endl;
    cout<<"|       \\|/ "  <<endl;
    cout<<"|        |  "  <<endl;
    cout<<"|       /|\\ "  <<endl;
    cout<<"|        |  "  <<endl;
    cout<<"|           "  <<endl;
    cout<<"==================="<<endl;
}
void hangmanboard2()
{
    cout<<"+--------+  "  <<endl;
    cout<<"|        |  "  <<endl;
    cout<<"|          "  <<endl;
    cout<<"|        "  <<endl;
    cout<<"|          "  <<endl;
    cout<<"|        "  <<endl;
    cout<<"|          "  <<endl;
    cout<<"|           "  <<endl;
    cout<<"==================="<<endl;
}
Topic archived. No new replies allowed.