Final Source Code for TripleX

After a bit of revision, I think it’s ready to be shared among you wonderful people. I want all the constructive criticisms.

#include
#include

void Prompt(int Difficulty)
{
std::cout << "You come across level " << Difficulty << “. The lock is rusted a bit. \nIt looks as if it need
s an input of three numbers to open.”;
}

bool PlayGame(int Difficulty)
{
Prompt(Difficulty);
int NumberOne = rand() % Difficulty + 1;
int NumberTwo = rand() % Difficulty + 1;
int NumberThree = rand() % Difficulty + 1;
int Product = NumberOne * NumberTwo * NumberThree;
int Sum = NumberOne + NumberTwo + NumberThree;

//Hinting

std::cout << “\n\n+ There are three slots for three numbers.”;
std::cout << "\n+ The product of the three numbers is " << Product;
std::cout << "\n+ The sum of the three numbers is " << Sum << “\n”;

//Player inputs guesses

int PlayerGuessOne, PlayerGuessTwo, PlayerGuessThree;
std::cin >> PlayerGuessOne >> PlayerGuessTwo >> PlayerGuessThree;
std::cout << "You guessed " << PlayerGuessOne << PlayerGuessTwo << PlayerGuessThree << “\n”;
int GuessSum = PlayerGuessOne + PlayerGuessTwo + PlayerGuessThree;
int GuessProduct = PlayerGuessOne * PlayerGuessTwo * PlayerGuessThree;

//Decision statement

if (GuessSum == Sum && GuessProduct == Product)
{
std::cout << “\nAs you tirelessly pick the lock, you hear a satisfying click and the door rolls open…
\n\n";
return true;
}
else
{
std::cout << "\n
As you pick the lock with your thieves tools, you hear a snap and now your kit is re
ndered useless.
\n\n”;
return false; //Returns to main()
}
}

int main()
{
srand(time(NULL));
int const MaxDifficulty = 5;
int LevelDifficulty = 1;
std::cout << “\n\nYou are a Rogue Adventurer looking to break into different levels of a prison.\n”;

while (LevelDifficulty <= MaxDifficulty) 
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear();
std::cin.ignore();
if (bLevelComplete)
{
    ++LevelDifficulty; 
}
}

std::cout << “Congratluations. You made it to the bottom of the prison. You hug your best friend, Tug.”;
return 0;
}

Privacy & Terms