IsIsogram() Function

Hello everyone!

This is what I came up with for the IsIsogram() function. Although, the function doesn’t check against capitalization. For Bulls and Cows, I would hate to lose because of capitalization and therefore, I would suggest handling the player’s input appropriately. For now, I am going to lower case the hidden word and the player’s input outside of this function. I’m sure the course goes over other ways to solve this issue.

/*
 Checks if the player's guess is an isogram.
 Note: This function doesn't handle capitalization check.
*/
bool UBullCowCartridge::IsIsogram(FString Word)
{
    for(int32 i = 0; i < (Word.Len() -1); i++)
    {
        for(int32 j = (i + 1); j < Word.Len(); j++)
        {
            if(Word[i] == Word[j])
                return false;
        }
    }

    return true;
}
1 Like

Hey that is really similar to mine!
The only thing I noticed is this line:

i < (Word.Len() -1)

I believe you do not need the “-1” if you are using “<” instead of “<=”, or else you are not gonna check the last char.

@LeonX

I think I forgot to add the equals sign, but you are right. You can scratch the -1 and do <. You don’t need to check the last letter in the top most loop.

Privacy & Terms