PlayGame() not working properly

After I changed from a for to a while loop, BullCowCount = BCGame.SubmitValidGuess(Guess) does not run.

You may well have solved this already, given that it has been a couple of months now, but I had exactly the same problem so I thought I would share the solution for others.

It appears as though the issue actually lies within GetValidGuess(). I had this:

FText GetValidGuess()
{
    EGuessStatus Status = EGuessStatus::Invalid_Status;
    FText Guess = "";
    
    do
    {
        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::Not_Isogram:
                std::cout << "Please enter a guess without repeating letters    .\n";
                break;
                
            case EGuessStatus::Wrong_Length:
                std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n";
                break;
                
            case EGuessStatus::Not_Lowercase:
                std::cout << "Please enter your guess in lower case.\n";
                break;
                
            default:
                break;
        }
        
        std::cout << std::endl;
    }
    while (Status != EGuessStatus::OK);
    
    return Guess;
}

If you look just above the switch statement you’ll notice I’m actually creating a new EGuessStatus variable called Status for each loop and that is being modified, but it is never updating the Status variable we initialise at the start of the function so while (Status != EGuessStatus::OK) never evaluates to true.

It’s just a simple case of changing:

EGuessStatus Status = BCGame.CheckGuessValidity(Guess);

To:

Status = BCGame.CheckGuessValidity(Guess);

Hope that helps :slight_smile:

2 Likes

Thank you so much! I myself have not guessed before!

Hello.

This is an old post, but I was having this same problem and looking through my code repeatedly.
It was a simple solution to a simple problem, but nevertheless I wanted to thank you for helping me solve it.
And the solutions is explained very well.

That’s it. Have a nice day.

Don’t mention it that’s what the community is there for.

Have a great weekend :wink: :slight_smile:

Privacy & Terms