TripleX - Final: Launch Codes

Hi everyone,

Finished the game, course was a lot of fun.

I didn’t difficult + difficulty but still struggle on level 5! Eesh.

#include <iostream>

#include <ctime>

void PrintIntroduction(int Difficulty)

{

    std::cout << "\n\n:: Welcome to the level " << Difficulty <<  "//SERVER\n"; 

    std::cout << ":: You need to enter the correct //CODE to continue\n";

}

bool PlayGame(int Difficulty)

{

    PrintIntroduction(Difficulty);

    const int CodeA = rand() % Difficulty + 1;

    const int CodeB = rand() % Difficulty + 1;

    const int CodeC = rand() % Difficulty + 1; 

    const int CodeSum = CodeA + CodeB + CodeC;

    const int CodeProduct = CodeA * CodeB * CodeC;

    //print sum and product to terminal

    std::cout << ":: There are (3) numbers in the //CODE\n";

    std::cout << "\n:: The //CODE (+) equals=" << CodeSum;

    std::cout << "\n:: The (x) of the //CODE equals=" << CodeProduct << std::endl;

    //store player guess

    int GuessA, GuessB, GuessC;

    std::cin >> GuessA >> GuessB >> GuessC;

    int GuessSum = GuessA + GuessB + GuessC;

    int GuessProduct = GuessA * GuessB * GuessC;

    //check player guess

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

    {

        std::cout << ":: Accessing next level of //CODE. Please wait. ::\n";

        return true;

    }

    else

    {

        std::cout << ":: ***ERROR*** ::\n";

        std::cout << ":: (LOCAL) + (FEDERAL) authorities are being notified. ::\n";

        std::cout << ":: SUCCESS: //CURRENT.LOCATION shared with (LOCAL) + (FEDERAL) authorities. Please Wait. ::\n";

        std::cout << ":: Attempt again? ::\n";

        return false;

    }    

}

int main()

{

    srand(time(NULL)); //create new random sequence based on time of day

    int LevelDifficulty = 1;

    const int MaxLevel = 5;

    

    while (LevelDifficulty <= MaxLevel) // loop game until all levels are completed

    {

        bool bLevelComplete = PlayGame(LevelDifficulty);

        std::cin.clear(); //clears errors

        std::cin.ignore(); //discards buffer

        if (bLevelComplete)

        {

            ++LevelDifficulty;

        }

        

    }

    std::cout << ":: Upload 100% //CODE complete\n";

    std::cout << ":: Launch Code PW == password123 ::\n";

    return 0;

}

1 Like

Incredible work!

1 Like

Privacy & Terms