Not incrementing MyCurrentTry

After renaming SubmitGuess to SubmitValidGuess, he said to double check it still works. When I did so , I found that the turn try wouldn’t increment even after submitting a 6 letter guess. I’m unsure why this is.

This is the code for submitting a valid guess :
`FBullCowCount FBullCowGame::SubmitValidGuess(FString Guess)
{
// increment the try number
MyCurrentTry++;

// setup a return variable
FBullCowCount BullCowCount;

// loop through all letters in the guess
int32 WordLength = MyHiddenWord.length();

for (int32 MHWChar = 0; MHWChar < WordLength; MHWChar++){

	// compare letters against the hidden 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++; //increment bulls
			}
			else {
				BullCowCount.Cows++;	//increment cows
			}
		}
	}
}
return BullCowCount;

}`

This is the switch statement :
`// loop continually until the user gives a valid guess
Ftext GetValidGuess()
{
Ftext Guess = “”;
EGuessStatus Status = EGuessStatus::Invalid_Status;
do
{
// get a guess from the player
int32 CurrentTry = BCGame.GetCurrentTry();
std::cout << “Try.” << CurrentTry << " Enter your guess : ";
std::getline(std::cin, Guess);

	EGuessStatus Status = BCGame.CheckGuessValidity(Guess);
	switch (Status)
	{
	case EGuessStatus::Wrong_Length:
		std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word. \n";
		break;

	case EGuessStatus::Not_Isogram:
		std::cout << "Please enter a isogram (a word with no repeating letters). \n";
		break;

	case EGuessStatus::Not_Lowercase:
		std::cout << "Please use only lowercase characters. \n";
		break;

	default:
		// assume the guess is valid
		break;
	}
	std::cout << std::endl;
} while (Status != EGuessStatus::OK); // keep looping until we get no errors
return Guess;

}`

I’m really confused about this, any help at all would be greatly appreaciated.

1 Like

Hi!
Your very beginning of the switch statement there:
EGuessStatus Status = BCGame.CheckGuessValidity(Guess);
should looks like:
Status = BCGame.CheckGuessValidity(Guess);

I got this same problem that it never get out of that loop but still its status was “OK”.
Hope this helps you too!

1 Like

@JubinBlack - Thanks solved the problem.

Still, do not understand why we need to remove EGuessStatus (enum class) before “Status”?
I’m missing something fundamental here - I guess

1 Like

I don’t remember how that worked, but if i remember right it was some problem with where that enum was declared or so. Dont have that code here now, but if i remember later i can check that and try to explain that reason. Cant promise anything yet.

1 Like

Hello @Sidharth_Thapliyal,

you need to put EGuessStatus Status = EGuessStatus::Invalid; before of the do-while loop.

FText GetValidGuess() // TODO change to GetValidGuess
{
	FText Guess = "";
	EGuessStatus Status = EGuessStatus::Invalid;
	do {
		int32 CurrentTry = BCGame.GetCurrentTry();

		// get a guess from the player
		std::cout << "Try " << CurrentTry << ". Enter your guess: ";
		std::getline(std::cin, Guess);

		Status = BCGame.CheckGuessValidity(Guess);

		switch (Status) {
		case EGuessStatus::Wrong_length:
			std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word." << std::endl;
			break;
		case EGuessStatus::Not_Isogram:
			std::cout << "Please enter a word without repeating letters." << std::endl;
			break;
		case EGuessStatus::Not_lowercase:
			std::cout << "No special characters and only lowercase letters allowed." << std::endl;
			break;
		default:
			break;
		}
		std::cout << std::endl;
	} while (Status != EGuessStatus::OK); // keep looping until we get no errors
	return Guess;
};

Cheers
Kevin

Privacy & Terms