Clarity

Took me 15 odd minutes to figure this out - now to watch the example in the video…

#include <iostream>
#include <string>


void PrintIntro();
void PlayGame();
std::string GetGuess();

// Global Variable
std::string Guess = "";


int main()
{
	PrintIntro();
	PlayGame();
	return 0; // Exit App
}

// Loop number of turns asking for guesses
void PlayGame()
{
	constexpr int NUMBER_OF_TURNS = 5;
	for (int Count = 1; Count <= NUMBER_OF_TURNS; Count++)
	{
		std::cout << "Guess " << Count << ".\n";
		GetGuess();
		std::cout << " You guessed " << Guess << "\n";
		std::cout << std::endl;
	}
}

// Intro
void PrintIntro()
{
	constexpr int WORD_LENGTH = 5;

	std::cout << "Welcome to Bulls and Cows, a fun word game!"
		<< std::endl
		<< "Can you guess the " << WORD_LENGTH << " letter isogram i'm thinking of?"
		<< std::endl;

	return;
}

// Get player input
std::string GetGuess()
{
	std::cout << "Enter your guess: ";
	std::getline(std::cin, Guess);
	return Guess;
}
1 Like

Privacy & Terms