I want to check if a char is one of the letters in a word(string), so I wrote like this:
1 2 3 4
for (int i = 0; i < word.length(); i++) {
if(letterForScan == word.charAt(i))
cout << "correct" << endl;
}
However, if the word contains two or more same letters, the output would be corresponding times of "correct". For example, if the word is "character" and the letterForScan is a, there would have two "correct" output. How could I make it only show "correct" only once?
if i use "break", how can i output two same letter at the same time? when i try, it would only output one letter at a time, but i want to show all same letters in a word once the guess is entered correctly.
but the words are randomly selected, not always will be 9 letters. Is there a way to make those underscore changes to the number corresponding to the word length?