My code after finishing the if/else statement lesson

#include <iostream>

int main()
{
    // Print welcome messages to the terminal
    std::cout << "You are 97, an agent who infiltrated the enemy lines in Afghanistan...";
    std::cout << std::endl;
    std::cout << "You reached the secret room where the agent by the codename of '43' is being held prisoner...";
    std::cout << std::endl;
    std::cout << "The room can be unlocked by entering the correct codes...";
    std::cout << std::endl;
    std::cout << "Enter the correct codes to continue..." << std::endl;

    const int CodeA = 4;
    const int CodeB = 9;
    const int CodeC = 6;

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


    // Print CodeSum and CodeProduct 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 << "Congratulations, you entered the correct codes";
    }
    else 
    {
        std::cout << "You entered the wrong codes and activated the alarm!" << std::endl;
        std::cout << "A guard saw you and killed you!";
    }

    return 0;
}
1 Like

Your code is really good! It is always ice seeing people taking pride in their code.

Privacy & Terms