BullCowCount.Bulls = WordLength vs. ==

Here is my original code:

FBullCowCount FBullCowGame::SubmitValidGuess(FString Guess)
{
//receives valid guess, increments turn, returns values

//increment turn number
MyCurrentTry++;

//setup a return variable
int32 WordLength = MyHiddenWord.length(); //assuming same length as guess

//loop through all letters in the hidden word
FBullCowCount BullCowCount;
for (int32 MHWChar = 0; MHWChar < WordLength; MHWChar++)
{
	//compare letters against the hidden word
	for (int32 GuessChar = 0; GuessChar < WordLength; GuessChar++)
	{
		if (Guess[GuessChar] == MyHiddenWord[MHWChar])
		{
			if (MHWChar == GuessChar)
			{
				BullCowCount.Bulls++;
			}

			else
			{
				BullCowCount.Cows++;
			}
		}
	}
}
if (BullCowCount.Bulls = WordLength)    <==
	bGameWon = true;
else
	bGameWon = false;

return BullCowCount;

}

I have marked the line in question with <==
So here’s an interesting question:
Why is it that when I use 1 equal sign, my console returns 5 bulls and 1 cow on an incorrect guess, and says that the player has won even though it’s incorrect, but putting a double equal sign makes it work normally?
If needed I can github my entire project, I was just lazy as it is late right now.
Thanks guys!

Those are two different operators.

  • *== sign check for equality of two things (if they are equal)
    You did a mistake here, you should type
    if (BullCowCount.Bulls == WordLenght) { … }
    The loop will check if BullCowCount.Balls is equal to WordLenght, and if it IS, it will execute statement inside { } --> it will ASSIGN bGameWon to true, in other words, bGameWon will get value TRUE.
    If BullCowCount.Balls is NOT equal to WordLenght, it will skip this loop and it will move to “else” statement, where bGameWon will get value FALSE.

  • = sign assigns a value to something.
    Lets say you have “int a = 5”.
    If you now write cout << a;
    it will write “5” on your console, because you assigned a value 5.

1 Like

Hello @TheTrueNameleSS1,

using “=” is an “assignment”. Using “==” is a “comparison” and is returning a boolean-value.

Kind regards
Kevin

Privacy & Terms