Course Progress

I am on lecture #24, using if and else in C++. I went a bit off-course and started tweaking with this because I was bored in class and I came up with this. I have experience with C# and Python, so that helped me greatly. Did my own tweaks with no internet help! (Actually quite proud of this since I didn’t know C++ 2 days ago!)

#include <iostream>

bool Game(int Level)
{
    //Introduction
    std::cout << "You are a special test subject from Triton." << std::endl;
    std::cout << "You need to find 3 codes for every room and try to escape." << std::endl;
    std::cout << "Your prize, is freedom." << std::endl;
    std::cout << "Good Luck!" << std::endl << std::endl;

    //Variables
    int Number1 = 3 * Level;
    int Number2 = 5 * Level;
    int Number3 = 6 * Level;
    int NumberSum = Number1 + Number2 + Number3;
    int NumberProduct = Number1 * Number2 * Number3;

    //Alert the player about the facts to get the number
    std::cout << "There are 3 integers from 0-9 in the code." << std::endl;
    std::cout << "The sum of the code is " << NumberSum << std::endl;
    std::cout << "The product of the code is " << NumberProduct << std::endl;
    std::cout << "Please make your guess now: " << std::endl;

    int PlayerGuessA, PlayerGuessB, PlayerGuessC;
    std::cin >> PlayerGuessA;
    std::cin >> PlayerGuessB;
    std::cin >> PlayerGuessC;

    int GuessSum, GuessProduct;

    GuessSum = PlayerGuessA + PlayerGuessB + PlayerGuessC;
    GuessProduct = PlayerGuessA * PlayerGuessB * PlayerGuessC;

    std::cout << "You entered: " << PlayerGuessA << PlayerGuessB << PlayerGuessC << "." << std::endl;

    if (NumberSum == GuessSum && NumberProduct == GuessProduct)
    {
        std::cout << "You are correct. You are not going to die. (maybe)" << std::endl << ">> Next Level";
        return true;
    }
    else
    {
        std::cout << "You are incorrect. You are going to die. (definately)" << std::endl << ">> Game Ending"; 
        return false;
    }
}

int main(){
    for (int i = 1; i <= 5; i++)
    {
        bool pass = Game(i);
        if(!pass)
        {
            break;
        }
    }

    return 0;
}
2 Likes

Keep up the great work with the course progress :100: