Here is my code

I think it reads quite good.

#include<iostream>
#include<string>

using namespace std;

void PrintIntro();
void PlayGame();
string GetGuess();
void PrintGuess(string PlayersGuess);


//entry point for the application
int main() 
{
	PrintIntro();
	PlayGame();

	return 0;
}

//introduce the game
void PrintIntro()
{
	constexpr int WordLength = 5;

	cout << "Welcome to Bulls and Cows" << endl;
	cout << "Can you guess the " << WordLength << " letter isogram I am thinking of?\n" << endl;
}


//playing the game
void PlayGame()
{
	constexpr int ITERATION = 5;

	for (int i = 0; i < ITERATION; i++)
	{
		PrintGuess(GetGuess());
	}
}

//get an input from the player
string GetGuess()
{
	string Guess = "";

	cout << "Enter your guess: ";
	getline(cin, Guess);

	return Guess;
}

//repeat the guess back to the player
void PrintGuess(string PlayersGuess) 
{
	string guess = PlayersGuess;
	cout << "Your guess was \"" << PlayersGuess << "\".\n" << endl;
}

I had initially went with defining another function for displaying the guess as you’ve done here.

One note about your PrintGuess function is that you either need to use guess in your cout line, or not bother with creating it at all as you’re not using it anywhere except during its initialization.

Yeah, you are right, thanks for the tip.

Privacy & Terms