Can someone check my code please? I did a little extra testing and tried "anagrammatize" and "anagramatizez". The code returned the answer as an anagram when it shouldn't be. Where is my mistake in the code
// returns true if number of times each character appears in both strings are the same
int check_for_anagram(string str1, string str2)
{
int ch1, ch2;
for (int i = 0; i < str1.size(); i++)
{
char ch = str1.at(i);
if (ch == str1.at(i++))
ch1++;
}
for (int j = 0; j < str2.size(); j++)
{
char ch = str2.at(j);
if (ch == str2.at(j++))
ch2++;
}
if (ch1 == ch2)
return true;
}
Message edited
// returns true if number of times each character appears in both strings are the same
int check_for_anagram(string str1, string str2)
{
int ch1, ch2;
for (int i = 0; i < str1.size(); i++)
{
char ch = str1.at(i);
if (ch == str1.at(i++))
ch1++;
}
for (int j = 0; j < str2.size(); j++)
{
char ch = str2.at(j);
if (ch == str2.at(j++))
ch2++;
}
if (ch1 == ch2)
return true;
}
Message edited