My for loop for lecture 18

#include <string>
#include <iostream>

using namespace std;

void PrintIntro();
string GetGuessAndPrintBack();

// the program starts here
int main()
{
	// define how often the user is asked
	constexpr int MAX_GUESSES = 5;
		
	PrintIntro();

	// ask the user X times
	for (int i = 1; i <= MAX_GUESSES; i++)
	{
		GetGuessAndPrintBack();
	}
	
	return 0;
}

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

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

	// repeat the guess back to him
	cout << "You guessed " << Guess << "." << endl;
	cout << endl;
	cout << "Unsure if that's wrong or right. The course isn't over yet :-)" << endl;
	cout << endl;
	return Guess;
}

Privacy & Terms