Bull Cow IsIsogram returning false after character is not repeated

Hi.I am facing a problem in Bulls and Cows. What is happening is that when I don’t repeat the 1st character then my IsIsogram function is returning false and if I repeat the character then my function doesn’t returns false.

Here’s my IsIsogram functions code:

bool UBullCowCartridge::IsIsogram(FString Word) const

{

//    int32 Index = 0;

//    int32 Comparison = Index + 1;

    

   for(int32 Index = 0, Comparison = Index + 1; Comparison < Word.Len(); Comparison++)

   {

       if(Word[Index] == Word[Comparison])

       {   

           return false;

       } 

   }

    return true;

You only have a single loop so you’re only checking the first character.

e.g. If the HiddenWord = “plaan” your loop does the following.

p == l
p == a
p == a
p == n

The a is never checked against the other a.

Yeah but even if I repeat the 1st character the it doesn’t return false.

Could you show that?

Sure

When the 1st character is repeated:

When the 1st character is not repeated:

Could you show the code where you call IsIsogram?

void UBullCowCartridge::ProcessGuess(FString Guess)

{

    if(Guess == HiddenWord) 

    {

        PrintLine(TEXT("Wow you guessed the word great!"));

        EndGame();

        return;

    }

    --Lives;

    if(Lives <= 0)//Check if lives > 0

    {

        ClearScreen();

        PrintLine(TEXT("Well Done!! You have lost the game."));

        PrintLine(TEXT("The hidden word is: %s"), *HiddenWord);

        EndGame();

        return; 

    }

    

    // Remove Life

    if(Guess.Len() != HiddenWord.Len()) //Check right Number of Characters

    {

        ClearScreen();

        PrintLine(TEXT("You have lost a life.Lives = %i"), Lives);

        PrintLine(TEXT("That ain't the word try again...    Can't belive you can't guess a simple word."));

        PrintLine(TEXT("The letter is only %i characters long"), HiddenWord.Len());

        return;

    }

    if(IsIsogram(Guess))                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

    {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

        PrintLine(TEXT("There are no repeating letters"));                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

        return;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

    }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     

    if (Guess != HiddenWord)                                                                                                                                                                              

    {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

        PrintLine(TEXT("You have lost a life.Lives = %i"), Lives);                                                                                                                                                                                     

        PrintLine(TEXT("That ain't the word try again...    Can't belive you can't guess a simple word."));                                                                                                                                                                                     

        return;       

    }

You used IsIsogram in this check. This is supposed to be checking for errors i.e. if it’s not an isogram you want to print a helpful message and return.

Thank you so much DanM for helping me solve this problem. Have a great day . :smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms