In the output i am always getting the number 1 rather than the length of our hidden word

Hey, I always get the letter ‘1’ as opposed to the length of the hidden word which in my case is “games”.

I have verified the code numerous times and here it is below.

void FBullCowGame::Reset()
{
constexpr int32 MAX_TRIES = 5;
const FString Hidden_Word = “water”;
MyMaxTries = MAX_TRIES;
MyHiddenWord = Hidden_Word;
MyCurrentTry = 1;

return;

}
bool FBullCowGame::IsGameWon()const
{
return false;
}

bool FBullCowGame::CheckGuessValidity(FString)const
{
return false;
}

//receives a valid guess, increament turn and returns the number of counts
FBullCowCount FBullCowGame::Submitguess(FString Guess)
{
//increament the turn number
MyCurrentTry++;
//setup the return variable
FBullCowCount BullCowCount;
//loop through all letters in the guess
int32 HiddenWordLength = MyHiddenWord.length();
for (int32 MHWChar = 0; MHWChar < HiddenWordLength; MHWChar++)
{
//compare the letters aggainst the hidden word
for (int32 GChar = 0; GChar < HiddenWordLength; GChar++)
{
//if they match then,
if (Guess[GChar]==MyHiddenWord[MHWChar])
{
if (MHWChar==GChar)//if they are in the same place against the hidden word
{

				BullCowCount.Bulls++;
				//increment bulls if they are in the same place
			}
			else
			{
				BullCowCount.Cows++;
				//increment cows if they are there but not in the same place
			}
		}										
	}
}
return BullCowCount;

}

bool FBullCowGame::IsIsogram()
{
return false;Preformatted text

1 Like

Do you mean you always get ‘1’ for the hidden word length?, because if so, then maybe the problem is in your PrintIntro method in the main.cpp file, at least in the code you provide, it seems there is no error.

1 Like

He is saying that he gets a one on top of the “Welcome to Bulls and Cows, a fun word game.”

1 Like

Hello dear @Ayush_Joshi,

Please provide a proper code presentation in here.
You can use the “preformatted text”-button. See here:
Unbenannt

Then it would be much easier to analyze the code you shared.

Cheers
OtenMoten

Privacy & Terms