My Code

He suggested that I show off my code if I thought it was good so here goes lol

#include
#include

using namespace std;

constexpr int WordLength = 5;
constexpr int GuessLimit = 5;

void PrintIntro();
string GetGuess();
void GiveResponse(string CurGuess, int GuessNum);

//The main function of this class
int main()
{
PrintIntro();
GetGuess();
return 0;
}

//Welcomes player to the game
void PrintIntro()
{
cout << “Welcome to Bulls and Cows!\nCan you guess the " << WordLength << " letter isogram?\n”;
cout << endl;
return;
}

//Acquires guess from player
string GetGuess()
{
string Guess = “”;
//Limits the amount of guesses a player can make
for (int GuessCount = 1; GuessCount <= GuessLimit; GuessCount++)
{
if (GuessCount <= 1)
{
cout << "Enter your first guess: ";
}
else
{
cout << "Enter your next guess: ";
}
getline(cin, Guess);
cout << endl;
GiveResponse(Guess, GuessCount);
}
return Guess;
}

//Gives appropriate response to player after a guess is made
void GiveResponse(string CurGuess, int GuessNum)
{
//Adjusts the grammar of the response based on GuessNum
string GuessName = “”;
switch (GuessNum)
{
case 1: GuessName = “st”;
break;
case 2: GuessName = “nd”;
break;
case 3: GuessName = “rd”;
break;
default: GuessName = “th”;
break;
}
//Outputs a string response to player
cout << "Your “<< GuessNum << GuessName <<” guess was: " << CurGuess << endl;
cout << endl;
return;
}

Privacy & Terms