#include #include using namespace std; int main() { string word = "dynamite"; char letter; cout << "Guess a letter: "; cin >> letter; // tell the user whether the letter they entered // is in the variable word // HINT: use a for loop with an if statement // -- and use a bool variable bool found = false; // while ( found == false ) // { for ( int i = 0 ; i < word.length() ; i++ ) { if ( word[i] == letter ) { found = true; } } if ( found == true ) { cout << "Yes, " << letter << " is in the word.\n"; } else { cout << "Nope, " << letter << " is not in the word.\n"; // cin >> letter; } // } // Now the user has to guess the word! cout << "Now the guess the word: "; string guess; cin >> guess; if ( guess == word ) { cout << "You got it!\n"; } else { cout << "Sorry, you guessed wrong.\n"; } // Compare two strings without using == for strings bool correct = true; if ( word.length() != guess.length() ) { correct = false; } else { for ( int i = 0 ; i < word.length() ; i++ ) { if ( word[i] != guess[i] ) { correct = false; } } } if ( correct ) { cout << "Yes, wow, good guess!\n"; } else { cout << "Sorry, you guessed wrong!\n"; } return 0; }