Lecture 19 Challenge Code

#include <iostream>
#include <string>

using namespace std;

void PrintIntro();
void PlayGame();
string GetGuess();
void PrintGuess(std::string &Guess);

int main() 
{
	// Psuedo code programming used to write comments first
	// So that we think naturally then code.

	PrintIntro();
	PlayGame();
	return 0;
}

void PlayGame()
{
	constexpr int NUMBER_OF_TURNS = 5;
	for (int count = 0; count < NUMBER_OF_TURNS; count++) {
		string Guess = GetGuess();
		PrintGuess(Guess);
	}
}

// Introduce the game
void PrintIntro() 
{
	constexpr int WORD_LENGHT = 5;
	cout << "\t\t<---------------------------";
	cout << endl << "\t\tWelcome to Bulls and Cow Game" << endl;
	cout << "\t\t---------------------------->" << endl;
	cout << "I have a word in my mind, which is " << WORD_LENGHT
		<< " letters in length and no letter is repeated" << endl;
	return;
}

string GetGuess() 
{
	// get a guess from the player
	cout << "Enter the guess: ";
	// use Camel case for unreal coding standards
	string Guess = "";
	getline(cin, Guess);
	return Guess;
}

void PrintGuess(std::string &Guess)
{
	cout << Guess << endl;
}

Thanks for sharing

Privacy & Terms