Is this alright?

It works.The question is, am I complicating it ?

#include
#include
using namespace std;

void introprint();
void PlayGame();
string Getguess();
void PrintGuess(string s);

//Entry point
int main ()
{
introprint();
PlayGame();
return 0;//Exit Applicatoin
}

void PlayGame()
{
//loop for number of guesses
constexpr int NUMBER_OF_GUESSES = 5;
for (int i = 1; i <= NUMBER_OF_GUESSES; i++)
{

	string Guess = Getguess();
	PrintGuess(Guess);
	cout << endl;
}

}
void introprint()
{
//introduction
constexpr int WORD_LENGTH = 5;
cout << “Welcome to the game.\n”;
cout << “Can you guess the " << WORD_LENGTH;
cout << " letter isogram that I’m thinking of?\n”;
cout << endl;
return;
}

string Getguess()
{
//Get the player’s guess
cout << "Please enter your guess: ";
string Guess = “”;
getline(cin, Guess);
return Guess;
}

void PrintGuess(string s)
{
//Repeat the player’s guess
cout << "You guessed " << s << endl;
}

Since there’s nothing to include, you can delete them

This is kind of overengineered:

If you wrote these functions to LEARN how to write functions, then you did well.

The drawback is, that the CPU has to create 2 variables and call two functions, although only only one variable and no function is needed (you even named the variables the same)

you can shorten all of this to:

cout << "Please enter your guess: ";
string Guess = "";
getline(cin,Guess);
cout << endl << "You guessed: " << Guess << endl;
1 Like

Privacy & Terms