Extra challenge

I did the extra challenge of asking the user to introduce the length word. I started by creating a new map from int32 to FString to have a map of words. The I ask the user to introduce the number of letters, transform the string to an integer and set the hidden word

TMap<int32, FString> LengthToIsogram{ {3, "sun"}, {4, "suit"}, {5, "phone"}, {6, "tuxedo"} };
	FString IsogramLengthString;
	int32 IsogramLengthInt;
	do
	{
		std::cout << "Introduce the length of the isogram you want to guess (between 3 and 7): ";
		std::getline(std::cin, IsogramLengthString);
		IsogramLengthInt = std::stoi(IsogramLengthString);
	} while (IsogramLengthInt < 3 || IsogramLengthInt >6);
	
	const FString HIDDEN_WORD = LengthToIsogram[IsogramLengthInt];
	MyHiddenWord = HIDDEN_WORD;

If the user introduces a number that is not between 3 and 6, it just asks again to do it. I could probably do it prettier with a message like “Length not available”, but for the moment this is fine.

did your code work i did mine differently

Privacy & Terms