The "if" challenge for part 25 (tripleX)

Here is my code so far for the TripleX game. I’ve made it to the IF section of the lectures.

#include <iostream>

int main()
{
    std::cout << "You are a new-hire level 0 tech at generic facility." << std::endl //intro message
    << "You are performing a task that requires a level 1 tech's tools..." << std::endl
    << "The tools are locked in the level 1 tech's tool box." << std::endl
    << "Crack the 3 pin code and get the tool without damaging the lock....." << std::endl << std::endl; //intro message

    const int CodeA = 4;
    const int CodeB = 7;
    const int CodeC = 2;


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

    std::cout << "There are three numbers in the code." << std::endl
    << "The numbers in the code add up to: " << CodeSum << std::endl
    << "The numbers in the code multiply to: " << CodeProduct << std::endl;

    int GuessA, GuessB, GuessC;

    std::cin >> GuessA >> GuessB >> GuessC;
    //std::cout << std::endl << "You have entered: " << GuessA << GuessB << GuessC;

    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;

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

        std::cout << "You're in! You got the tool."; //Winning message

    } else{
        std::cout << "You entered the wrong code and jammed the lock." << std::endl << "You get fired at the end of the shift."; //Losing message
    }

    return 0; //end program no error
}

Privacy & Terms