Word.Len() - 1 doesn't return the last character

In the Bull Cow game I noticed that Word[Word.Len()] doesn’t return a placeholder as stated in the course it actually does return the last character and so if I had an Isogram and the word I entered was ‘test’ then it wasn’t getting detected by my logic because ’ i < Word.Len() - 1’ was stopping my loop after the ‘s’ and not the ‘t’. Is it possible I’m misunderstanding my own logic? Lol

    for (int32 i = 0; i < Guess.Len() - 1; i++)
    {
        for (int j = 0; j < Guess.Len() - 1; j++)
        {
            if (Guess[i] == Guess[j] && i != j) 
            {
                return true;
            }
        }
    }

That code will not return true for the word test but if I remove the ‘- 1’ it does

That should be return false. What you have is saying if it has a repeating character return true.

Yeah I noticed that after adding it, I also accidentally made j an int instead of int32. It’s funny how that works. Seems like every-time I post something I immediately notice things wrong with it XD. Thanks for the feedback. Also thanks with that other problem I had the other day. Even after fixing that though using the same logic it was still detecting say letter but not test.

Never mind I see it is because when I check to see if it j < Guess.Len() it checks the last position but not the actual placeholder on the end. Also I noticed too I was checking against character’s I was already checking using the method I used above so I went back, changed j = 0 to j = i + 1.

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

Privacy & Terms