Here's my triplex code, so far

This is how it looks so far, I’ve tried doing ASCII art and I suck at it. Instead of just adding a string at the end I added an if statement on when to print the congratulation message.

//  # = Pre Processor directive and the directive is to include iostream library.
#include <iostream>

void PrintIntroduction(int Difficulty)
{
// Intro : Expression Statements
    std::cout << "\n\nYou are a thief cracking a series secure vaults. Level " << Difficulty;
    std::cout << "\nEnter the correct sequence to crack the vault's security system.\n\n";
}

bool PlayGame(int Difficulty)
{
    PrintIntroduction(Difficulty);

    // Declaration Statements: Declaring 3 numbers
    const int CodeA = 2, CodeB = 4, CodeC = 8;

    const int CodeSum = CodeA +CodeB +CodeC;
    const int CodeProduct = CodeA* CodeB * CodeC;


    // Expression Statements
    std::cout << "++We have three numbers in our code.\n\n";
    std::cout << "++The sum of the numbers is: " << CodeSum;
    std::cout << std::endl << std::endl;
    std::cout << "++Multiplying the numbers gives: " << CodeProduct << std::endl;

    int GuessA, GuessB, GuessC;

    std::cout << "\nEnter your guess number one: ";
    std::cin >> GuessA;
    std::cout << "\n\nEnter your guess number two: ";
    std::cin >> GuessB;
    std::cout << "\n\nEnter your guess number three: ";
    std::cin >> GuessC;

    //Store Player Guess
    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;

    std::cout << "\n\nThe sum of your entered numbers is: " << GuessSum;
    std::cout << "\n\nMuntiplying the numbers gives the product: " << GuessProduct;
    
    std::cout << std::endl << std::endl;

    //Check if the players guess is correct or not.
    if (CodeSum==GuessSum){
    	std::cout << "You cracked the first vault!!!\n\nNow move on to crack the next vault.";
        return true;
    }
    else{
    		std::cout << "You entered the wrong code and triggerd a facility lockdown and got caught.\n\nRetry cracking the vault again.";
            return false;
    }
}

// main function, the heart of code where the compiling of the code starts from.
int main()
{
    int LevelDifficulty = 1;
    const int MaxDifficulty = 5;


    while (LevelDifficulty <= MaxDifficulty) //Loops the game until all levels are completed.
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear(); // Clears any errors
        std::cin.ignore(); // Discards the buffer
        if (bLevelComplete)
    {
        ++LevelDifficulty;
    }
    }
       if (LevelDifficulty>5)
       {
           std::cout << "\n\nCongratulations on scoring your biggest heist yet.";
       }
    return 0;
}

1 Like

Practice makes perfect! You can also find websites with ascii that you can copy and paste.

1 Like

1 Like

Privacy & Terms