TripleX Final!

#include

#include

using namespace std;

void PrintIntroduction(int Difficulty)

{

cout << "\nYour grades have been lacking, so you decide that you must cheat. This will be hard, however." << endl << endl;

cout << "You have broken into your math teacher's homeroom to steal the answers to an upcoming test." << endl;

cout << "However, to break into the safe, you need to enter a 3 digit code...\n\n"; // Transition to Backend code

cout << "Level " << Difficulty;

}

bool PlayGame(int Difficulty)

{

PrintIntroduction(Difficulty);

// Declare 3 number code

const int CodeA = rand() % Difficulty + Difficulty;

const int CodeB = rand() % Difficulty + Difficulty;

const int CodeC = rand() % Difficulty + Difficulty;

const int CodeSum = CodeA+CodeB+CodeC;

const int CodeProduct = CodeA*CodeB*CodeC;

//Print Sum to Terminal

cout << endl << endl;

cout << "There are 3 numbers in your code..." << endl;

cout << "The code adds up to: " << CodeSum << endl;

cout << "The code multiplys to give: " << CodeProduct << endl;

cout << "(Make sure to add a space between each digit)" << endl;

cout << endl;

int GuessA, GuessB, GuessC;

//Store Player Guess

cout << "What is the code? ";

cin >> GuessA >> GuessB >> GuessC;

int GuessSum = GuessA + GuessB + GuessC;

int GuessProduct = GuessA*GuessB*GuessC;

if (GuessSum == CodeSum && GuessProduct == CodeProduct)

{

    cout << "You beat level " << Difficulty << ". Moving on to the next level." ;

    return true;

}

else

{

    cout << "You were not successful, and you've been caught by the headmaster. Try again. \n";

    return false;

}

}

int main()

{

srand(time(NULL)); // Random sequence based on time of day

const int MaxDifficulty = 5;

int LevelDifficulty = 1;

while (LevelDifficulty <= MaxDifficulty) // Loop game until completed

{

    bool bLevelComplete = PlayGame(LevelDifficulty);

    cin.clear();

    cin.ignore();

    if (bLevelComplete)

    {

        ++LevelDifficulty;

    }

}

cout << "\n\n You take the sheet of papers. B-but, they're blank?! It was a trap all along... and the safe starts to alarm.\n\n";

cout << "GAME OVER";

return 0;  

}

1 Like

Congratulations on finishing this.

Privacy & Terms