Not getting an error message

My code works fine, and I get the correct error message about word length in my program, but the error that is supposed to present itself in the “Error List” (‘GetValidGuess’: not all control paths return a value) does not appear. My code is exactly the same as Ben’s, and works as expected. Could it just be a newer version of Visual studio that recognizes that the code is safe? I guess this is a good “problem” to have, but I want to make sure my code is correct.

Here is my code in case you doubt me:

FText GetValidGuess()
{
	EGuessStatus Status = EGuessStatus::Invalid_Status;
	do {
		// get a guess from the player
		int32 CurrentTry = BCGame.GetCurrentTry();
		std::cout << "Try " << CurrentTry << ". Enter your guess: ";
		FText 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.!\n";
			break;
		case EGuessStatus::Not_Isogram:
			std::cout << "Please enter an Isogram(Word without repeating letters)!\n";
			break;
		case EGuessStatus::Not_Lowercase:
			std::cout << "Please enter your guess in lowercase!\n";
			break;
		default:
			return Guess;
		}

		return Guess;
	} while (Status != EGuessStatus::Ok);//keep looping until no errors present
}

Oops never mind I figured it out. For whatever reason I had 2 instances of “return Guess;” (one within the loop and one outside the loop). If anyone stumbles upon this post please ignore :slight_smile:

Hey very interesting, because I don’t have 2 instances of “return Guess” in my code, but also do not receive any warnings.

[code] FText GetValidGuess()
{
EGuessStatus Status = EGuessStatus::Invalid_Status;
do
{
// get a guess from the player
int32 CurrentTry = BCGame.GetCurrentTry();
std::cout << "Try " << CurrentTry << ". Enter your guess: ";
FText 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.\n";
		break;

	case EGuessStatus::Not_Isogramm:
		std::cout << "Please enter word without repeating letters.\n";
		break;

	case EGuessStatus::Not_Lowercase:
		std::cout << "Please enter lowercase letters.\n";
		break;

	default:
		return Guess;
	}
	std::cout << std::endl;
} while (Status != EGuessStatus::Ok); // keep looping until we no longer receive errors

} [/code]

1 Like

I had the same issue, for me a “Clean Solution” helped me in getting the warning. Find it under Build-> Clean Solution, and then rebuild your code with ctrl+F5

1 Like

Privacy & Terms