Clarity class 27

this is my code for this section

#include <iostream>
#include <string>

using namespace std;

void printIntro()
{
	constexpr int WORD_LENGHT = 9;
	// introduce the game and staff
	cout << "Welcom to bulls and cows  " << endl;
	cout << "Can you guess the " << WORD_LENGHT;
	cout << " I'm thinking of ?" << endl;
	return;
}

string getGuess()
{
	// get a guess from the player
	string Guess = "";
	cout << "enter your guess: ";
	getline(cin, Guess);
	return Guess;
}

void printGuess(string Guess)
{
	// Repeat the guess back
	cout << endl << "your guess " << Guess << endl;
}

void PlayGame()
{
	constexpr int NUMBER_OF_TURNS = 5;

	// loop for the number of turns asing for guesses
	for (int i = 1; i <= NUMBER_OF_TURNS; i++)
	{
		printGuess(getGuess());
	}
}

// the entry point of the app
int main()
{
	printIntro();
	PlayGame();
	getchar();
	return 0;
}



1 Like

My code for Clarity

#include <iostream>
#include <string>

using namespace std;

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

// the entry point 
int main()
{
	PrintIntro();

	PlayGame();
		
	return 0;
}

void PlayGame()
{
	// loop for the number of turns asking for guesses
	constexpr int NUMBER_OF_TURNS = 5;
	for (int i = 0; i < NUMBER_OF_TURNS; i++)
	{
		string Guess = GetGuess();
		// print the guess back to them
		cout << "Your guess was: " << Guess << endl << endl;
	}
}

//introduce the game
void PrintIntro()
{
	constexpr int WORD_LENGTH = 5;
	cout << "Welcome to Bulls and Cows, a fun word game.\n";
	cout << "Can you guess the " << WORD_LENGTH << " letter I'm thinking of?\n";
	cout << endl;
	return;
}

string GetGuess()
{
	// get a guess from	the player
	cout << "Enter your guess: ";
	string Guess = "";
	getline(cin, Guess);

	return Guess;
}

Privacy & Terms