+3 from nowhere in GetBullCows

for (int32 Index = 0; Index  < Guess.Len(); Index++)
    {
        if (HiddenWord.GetCharArray().Contains(Guess[Index]))
        {
            if (HiddenWord[Index]==Guess[Index])
            {
                BullCount++;
            }
            else
            {
                CowCount++;
            }
        }
    }

I wrote the code like that and i got a +3 for cows. Why is this happening?
Edit: It’s about Cows Variable at ProcessGuess but i still can’t understand why.

Code looks fine to me. Your problem probably lies elsewhere. btw you can use FindChar

for (int32 Index = 0; Index  < Guess.Len(); Index++)
{
    int32 FindIndex;
    if (HiddenWord.FindChar(Guess[Index], FindIndex))
    {
        if (Index == FindIndex)
        {
            Count.Bulls++;
        }
        else
        {
            Count.Cows++;
        }
    }
}

Its about the Cows variable at ProccessGuess.
int32 Bulls,Cows;
I wrote it like that and it happened. I saw this later but still can’t understand why.

Sorry I forgot to reply to you. That would mean those variables are uninitialised and reading uninitialised variables is undefined behaviour. You need to initialise them

int32 Bulls = 0;
int32 Cows = 0;

Privacy & Terms