Bulls and Cows still Zero post-lecture, in-game

I just did (or I think I did) a letter-for-letter comparison of the code Ben wrote, and it compiles successfully, but when I run the game, it always gives me zero bulls, zero cows. I figure the error is somewhere in the snipped screenshots here. Any help appreciated.

are you sure MyHiddenWord[ i ] isn’t suppose to be MyHiddenWord [ j ] ?

Because j seems to be what is controlling what letter of MyHiddenWord is being compared.

Thanks for replying, LifePartTwo.

As far as I can tell, it is supposed to be MyHiddenWord[i] in the case of my line 45.

Here’s Ben’s github changes at the end of this lecture:

I also did a check on changes to the other files, and they seem to be simpatico. I haven’t wrapped my head around the idea that there could be something wrong with the “Bulls” and “Cows” whenever those are covered. It would seem that doing Bulls++ adds 1 to what Bulls represents, so it should work. I have the zip of my project ready to upload, but still trying to see if it’s okay to do this, in the forum rules.

post it on github. There is github extention for visual studio that interacting with your github account pretty easy.

btw. this is the most update version of the code on github.

// receives a VALID guess, incriments turn, and returns count
FBullCowCount FBullCowGame::SubmitValidGuess(FString Guess)
{
MyCurrentTry++;
FBullCowCount BullCowCount;
int32 WordLength = MyHiddenWord.length(); // assuming same length as guess

// loop through all letters in the hidden word
for (int32 MHWChar = 0; MHWChar < WordLength; MHWChar++) {
	// compare letters against the guess
	for (int32 GChar = 0; GChar < WordLength; GChar++) {
		// if they match then
		if (Guess[GChar] == MyHiddenWord[MHWChar]) {
			if (MHWChar == GChar) { // if they're in the same place
				BullCowCount.Bulls++; // incriment bulls
			}
			else {
				BullCowCount.Cows++; // must be a cow
			}
		}
	}
}
if (BullCowCount.Bulls == WordLength) {
	bGameIsWon = true;
}
else
{
	bGameIsWon = false;
}
return BullCowCount;

}

Seems
if (Guess[GChar] == MyHiddenWord[MHWChar]) is using the different counter variables.

1 Like

Thanks, it’s solved now!

How did you solve it? I’m having the same issue.

Privacy & Terms