How come the bulls variable resets at every turn

Hello,

I’m a bit confused as to how the bulls counter in the console manages to reset for example, the first turn he gets 2 bulls and the 2nd turn he gets 3 , How Come? when did it reset back to zero in the code? if its one variable shouldn’t the bulls in this case be 5?

Thank you

In the SubmitGuess function itself; it resets the value.

FBullCowCount FBullCowGame::SubmitGuess(Fstring)
{

		// set up a return variable
	FBullCowCount BullCowCount;
	
	return BullCowCount;
}

//set up a return variable we created a new Struct called “BullCowCount.”

The answer is that when the function ends; after returning the information back to your main.cpp struct; you no longer have the created “BullCowCount” inside of the Submit function. It is a little confusing; because in the lecture the same name is given to the struct in your main.cpp file- but these are not the same.

So as your run the loop in main.cpp; it re-creates the ‘BullCowCount’ struct which is initiialized as:

struct FBullCowCount
{
	int32 Bulls = 0;
	int32 Cows = 0;
};

in your header file.

Great question; made me think of why this is happening! Hope this helps.

Privacy & Terms