My way of "checking" lowercase

I have personally not done it the same way as the videos. In my case, instead of checking if the word is composed of only lowercase, I compare the letters directly, independently of if they are uppercase or lowercase.

To do this, I simply converted all the letters to lowercase in the SubmitValidGuess() method, like this

FBullCowCount FBullCowGame::SubmitValidGuess(FString Guess)
{
	MyCurrentry++;

	//setup a return variable
	FBullCowCount BullCowCount;
	int32 WordLength = MyHiddenWord.length(); //assuming same length as guess
	
	
	//loop through all the letters in the guess
	for (int32 i = 0; i < WordLength; i++) {
		//compare letters against the hidden word
		for (int32 j = 0; j < WordLength; j++) {
			//if they match
				//increment bulls if they are in the same place
				//increment cows if they are not
			if ((tolower(Guess[i]) == tolower(MyHiddenWord[j])) && (i == j)){
				BullCowCount.Bulls++;
			}
			else if ((tolower(Guess[i]) == tolower(MyHiddenWord[j])) && (i != j)) {
				BullCowCount.Cows++;
			}

		}
	}
	if (BullCowCount.Bulls == WordLength)
	{
		bGameWon = true;
	}
	else {
		bGameWon = false;
	}
	return BullCowCount;
}

I checked and it works well. The character \0 and any input with an space is recorded as a word of incorrect length.

1 Like

Privacy & Terms