Need some help in my first Hangman game.

Alright so i made my first hangman game but one problem i seem to be running in is that my validation check for "already used letters" dose not seem to be working it seems like the program just skips the validation code but i dont see why or how. Help would be appreciated.

The validation code for checking already used letters starts from line 36 if there is anything else let me know this is the code for the whole program btw.

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
  // Hangman using functions and vectors Chapter 5 Exercise.

#include <iostream>
#include <string>
#include <cstdlib>
#include <list>
#include <ctime>
#include <vector>
#include <cctype>
#include <algorithm>

using namespace std;

// Max Try's for the game before the person is hanged.
const int maxGuesses = 10;

string playerGuess();
string guessCheck(string guess);

int main(){
    guessCheck(playerGuess());
    return 0;
}

string playerGuess()
{
    string guess = "";
    string used = "";

    // Taking the players guess.
    cout << "Please enter your guess in CAPITAL letters only!! thank you: ";
    cin >> guess;

    cout << endl;

    // Checking if users guess has not already been used before.
    while(used.find(guess) != string::npos){
        cout << "You have already guessed " << guess << " before!" << endl;
        cout << "Please enter a new guess: ";
        cin >> guess;
    }

    used += guess;

    return guess;

}

string guessCheck(string guess){
    // Intiallizing vectors & variables.
    vector<string> words;
    words.push_back("INVINSIBLE");
    words.push_back("DAMAGE");
    words.push_back("BEAUTIFUL");

    srand(time(0));
    random_shuffle(words.begin(), words.end());
    const string theWord = words[0];

    int wrongChoice = 0;
    string soFar(theWord.size(), '_');

    cout << "\nSo far you have " << soFar << "\n\n";

    // Checking players guess.
    while(maxGuesses != wrongChoice && soFar != theWord){
        if(theWord.find(guess) != string::npos){ // If the guess is correct.
                cout << "Yes thats right! " << guess << " is in the word.\n";

                // Updating words gussed so far.
                for(int i = 0; i < theWord.length(); ++i){
                    if(theWord[i] == guess[0]){
                        soFar[i] = guess[0];
                    }
                }

                // Displaying words guess so far.

                cout << "So far you have " << soFar << "\n\n";

                if(soFar != theWord){
                    guess = playerGuess();
                }
        }
        else{ // If user guess is wrong.
            cout << endl << "Wrong Guess! \n";
            wrongChoice++;
            if(soFar != theWord){
                    guess = playerGuess();
            }
        }
    }

    // If the max tries have been reached.
    if(maxGuesses == wrongChoice){
        cout << "You have been hanged!! your lifeless body swings around as the crowd watches!!!" << endl << "the word was" << theWord << " by the way ;)";
    }
    else{ // If not then the player wins.
        cout << "You guessed it!! you live to see another day yay!!!" << endl;
    }

}
Line 28, this variable is reset every time the function is called. I am almost sure this is not what you intended.
Oh my god lol i cant believe i missed that :x hahaha thank you my friend :)
Topic archived. No new replies allowed.