Hi. I'm trying to finish my program on hangman but I jsut can't seem to find the last mistake. The only proglem with the code is that when I enter a letter that exists in the word, it appears to fill that letter with every blank. Lets say the word is "CHICKEN". If I enter the letter "c" (which touppers to "C") it will output "CCCCCCC". And If I enter "n", it will change all the letters to "NNNNNNN."
Help would be much appreciated.
while ((wrong < Max_Wrong) && (so_Far != the_Word))
{
cout << "You have " << (Max_Wrong - wrong);
cout << " chances left.\n";
cout << "You have used the letters:\n" << used << endl;
cout << "So far, the word is:\n\n " << so_Far << endl;
char guess; //letter guess
cout << "Enter a letter:";
cin >> guess; //input letter
guess = toupper(guess); //lower to upper
//check if letter already entered
while (used.find(guess) != string::npos) //npos string lib
{
cout << "You have already entered " << guess << endl;
cout << "Enter a letter:";
cin >> guess;
guess = toupper(guess); //lower to upper
}
used += guess; //records letter and after
if (the_Word.find(guess) != string::npos) { //checks if guess is in called string
cout << guess << " IS in the word,\n";
for (int i = 0; i < the_Word.length(); ++i) //loops throught the word
{
if (the_Word[i == guess]) //check if guess is in word
{
so_Far[i] = guess;
}
}
}
else
{
cout << guess << " IS NOT in the word.\n";
++wrong;
}