#if the amount of distnict characters in string is odd print CHAT WITH HER! else print IGNORE HIM!

8 messages · Page 1 of 1 (latest)

golden lintel
#
#include <iostream>
using namespace std;
int main()
{
    string s = "wjmzbmr";
    //if the amount of distnict characters in string is odd print CHAT WITH HER! else print IGNORE HIM!

    int count = 0;
    for (int i = 0; i < s.length(); i++)
    {
        for (int j = i + 1; j < s.length(); j++)
        {
            if (s[i] == s[j])
            {
                count++;
                break;
            }
        }
    }

    if (count % 2 == 0)
    {
        cout << "CHAT WITH HER!";
    }
    else
    {
        cout << "IGNORE HIM!";
    }
}```
could someone help me with this? I expected the output to be Chat with her
it must be with the way I'm comparing
violet ospreyBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

chilly gull
#

did you debug it :)

#

did you verify what count is?

#

did you step trough the code to figure out what it's doing wrtong?

rain oyster
#

that for loop is not counting the number of distinct characters ;)

echo trench
#

go learn what a histogram is

violet ospreyBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.