I'm a newbie trying to create a word guess game and I'm having trouble with the simplest part. I'm trying to create a for loop that checks the string wordToGuess for the char guessletter. The problem is if it prints the statement i amount of times. How can I prevent this but still indicate whether or not the letter is in the string?
for (i = 0; i < WORD.length()-1; i++)
{
if (WORD.at(i) == guessletter)
{
cout << "That's right! The letter " << guessletter << " is in the word." << endl;
}
#include <iostream>
usingnamespace std;
int main()
{
string word = "Hello";
char guessletter = 'o';
if (word.find(guessletter) != string::npos)
cout << "That's right! The letter " << guessletter << " is in the word." << endl;
cin.ignore();
return 0;
}