TripleX if/else statements - This is why I never finish tutorials!

#include <iostream>

int main()

{

    //Output introduction text to the terminal.

    std::cout << "Welcome to the Net3X mainframe access portal...\nUser credentials not verified!\n";

    std::cout << "System maintenance mode engaged.\n";

    //set the values of our code digits.

    const int CodeOne = 4;

    const int CodeTwo = 4;

    const int CodeThree = 9;

    bool SumCorrect = false;

    bool ProductCorrect = false;

    //set the values of our hint text.

    int CodeSum = CodeOne+CodeTwo+CodeThree;

    int CodeProduct = CodeOne*CodeTwo*CodeThree;

    //Output hint text to ther terminal.

    std::cout << "\n+ There are 3 numbers in the code.\n";

    std::cout << "+ The codes add up to: " << CodeSum << "\n";

    std::cout << "+ The code multiples to equal: " << CodeProduct << "\n";

    std::cout << "+ Enter the correct codes to continue...\n";

    int GuessA, GuessB, GuessC;

    

    std::cout << "\n\nPlease input first digit: ";

    std::cin >> GuessA;

    std::cout << "\nPlease input second digit: ";

    std::cin >> GuessB;

    std::cout << "\nPlease input third digit: ";

    std::cin >> GuessC;

    std::cout << "\nUser Input: " << GuessA << "-" << GuessB << "-" << GuessC;

    int GuessSum = GuessA + GuessB + GuessC;

    int GuessProduct = GuessA * GuessB * GuessC;

    std::cout << "\nGuess Sum: " << GuessSum << "\nGuess Product: " << GuessProduct;

    if(GuessSum == CodeSum)

    { //If Sum is correct, tell the player!

        std::cout << "\nCode Sum is correct!";

        SumCorrect = true;

    }

    else

    { //Otherwise, remind the player what the sum needs to equal.

        std::cout << "\nCode Sum needs to equal: " << CodeSum;

        SumCorrect = false;

    }

    if(GuessProduct == CodeProduct)

    { //If the Product is correct, tell the player!

        std::cout << "\nCode Product is correct!";

        ProductCorrect = true;

    }

    else

    { //Otherwise, remind the player what the product needs to equal.

        std::cout << "\nCode Product needs to equal: " << CodeProduct;

        ProductCorrect = false;

    }

    if(SumCorrect && ProductCorrect)

    { //If both are correct, the player wins!

        std::cout << "\nYou win!";

        return 0;

    }

    else

    { //Otherwise, the player loses!

        std::cout << "\nYou lose!";

        //To-do: Implement some way to keep the game going till the player wins.

    }

    return 0;
}

I go way off the rails, get ideas, modify things too far, and then lose pace with the tutorial. :rofl:

1 Like

That’s when you learn the most! Great job!

Privacy & Terms