Could someone please explain to me why this code isn't working?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void letter_check (string letterGuess, string theWord)
{
int i = 0, length = theWord.size();
for (i=0; i<length; i++)
{
if (letterGuess == theWord.at(i))
cout << "The letter " << letterGuess << " is in the word!" << endl;
else
cout << "The letter " << letterGuess << " is not in the word." << endl;
}}
have a think about what is happening here and step through the code 1 line at a time & note down the value of the variables & what action is carried out as a result of these values.
If letterGuess is "a" and theWord is "Freda", what happens?
Also think about the type of your variables - should letterGuess be string?
Should there be a variable to count how many times a specific char is found?