I’d say most of your problems come down to this line:
while(x!=word[i]);
As the comments suggest, word
is your modified word, not the word list. But also, i
is the wrong index. So save the word index you chose earlier:
size_t wordIndex = rand() % 17;
string word = wordList[wordIndex];
Then change your do
loop condition:
while (x != wordList[wordIndex]);
I’d also recommend that you don’t use using namespace std;
.
You could argue about the use of rand()
, but it might not be worth it. Just be aware that rand()
has shortcomings and better alternatives exist.
solved Word Guessing Game C++