Sharing MY progress in Triple X game upto the usage of if and else

#include <iostream>
using namespace std;

int main()
{
    // Intro for the game to be printed in the terminal
    cout << "You are a part of a top secret agent taskforce and your mission is to break into a higly secure vault...." << endl;
    cout << "You being the brain of the team...., The task is on you to find the correct code to bypass the security..!!" << endl << endl;
    
    // Declaring our 3 number code
    int CodeA = 4, CodeB = 3, CodeC = 2;
    
    int CodeSum = CodeA + CodeB + CodeC;
    int CodeProduct = CodeA * CodeB * CodeC;

    //printing the sum and product to the terminal
    cout << "> The code consists of three numbers.."<< endl;
    cout << "> The code adds-up to : " << CodeSum << endl;
    cout << "> The codes multiply to give : " << CodeProduct << endl;


    int CodeAInput, CodeBInput, CodeCInput;

    cin >> CodeAInput >> CodeBInput >> CodeCInput;
    
    int GuessSum = CodeAInput + CodeBInput + CodeCInput;
    int GuessProduct = CodeAInput * CodeBInput * CodeCInput;

    if (GuessSum == CodeSum && GuessProduct == CodeProduct )
    {
        cout << "**Level 1 Security Access Granted**" << endl << "Now You need to hack into level 2 security terminal";
    }
    else
    {
        cout << " XXX Security Breach Detected XXX " << endl << "You have been found";  
    }
    
    return 0;
}
1 Like

Welcome to the community! Some nice clean code there! Keep it up!

Here is my code I have written so far. :smiley:

#include <iostream>

int main()
{
    // Introduction of the game
    std::cout << "The year is 2045. Templars have control of the Pieces of Eden." << std::endl;
    std::cout << "You are an Assassin breaking into a Templar vault that has Pieces of Eden to retrieve them." << std::endl;
    std::cout << "Every Piece of Eden is kept in a secured chamber that requires 3-digit PIN code..." << std::endl;
    std::cout << "You need to enter the correct codes to unlock the chamber..." << std::endl;
    
    const int CodeA = 4;
    const int CodeB = 5;
    const int CodeC = 9;

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

    // Print CodeSum and CodeProduct (Hints) to the terminal
    std::cout << std::endl;
    std::cout << "+ There are 3 numbers in the code" << std::endl;
    std::cout << "+ The codes add-up to: " << CodeSum << std::endl;
    std::cout << "+ The codes multiply to give: " << CodeProduct << std::endl;

    int GuessA, GuessB, GuessC;
    std::cin >> GuessA;
    std::cin >> GuessB;
    std::cin >> GuessC;
    
    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;

    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "GREAT!! You have retrieved a Piece of Eden." << std::endl;
    }
    else
    {
        std::cout << "OH NO!! You have triggered the Lockdown sequence." << std::endl;
    }

    return 0;
}

Privacy & Terms