string Foo(string letter)
{
for (int j = 0; j < (int)alphabet.length(); j++)
{
if (letter[0] == (alphabet[j]));
return "SUCCESS";
}
return "FAILURE";
}
alphabet = "Test";
cout << Foo("f") << endl;
This prints SUCCESS even thought it shouldn’t. What’s wrong with my comparison operator??
You have an empty
ifimmediately followed byreturn "SUCCESS";Remove that semicolon: