Code not working

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;


}}
You haven't said what is not working:

my guess will be the comparison between std::basic_string<char> and char on line 7. Quick fix:

void letter_check (char letterGuess, string theWord)
Hi utarinsyis,

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?

Hope all goes well :+)
Topic archived. No new replies allowed.