TripleX Thingy Mabob

My First code :))

#include <iostream>
#include <ctime> 

void PrintIntroduction(int Difficulty)
{
    std::cout << "\n\nYou are stuck in alternate dimension " << Difficulty;
    std::cout << " and you must get back to the real world! \nIn order to get back, you need to enter the correct codes Buzz Buddy...\n\n";
}

bool PlayGame(int Difficulty)
{
    PrintIntroduction(Difficulty);

    // declaring 3 number code 
    const int CodeA = rand() % Difficulty + Difficulty;
    const int CodeB = rand() % Difficulty + Difficulty;
    const int CodeC = rand() % Difficulty + Difficulty;

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

    // Print sum and product to the terminal
    std::cout;
    std::cout << "+ There are 3 numbers in the code.";
    std::cout << "\n+ The code adds up to: " << CodeSum;
    std::cout << "\n+ The code multiply to give: " << CodeProduct << std::endl;


    //Store player guesses

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

    // Guess sum and product to see if correct


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

    if (GuessSum == CodeSum && GuessProduct == CodeProduct) 
    {
        std::cout << "\nBuzz Buzz, you got it! Beam Me Up!";
        return true;
    }
    else
    {
        std::cout << "\nDang, that's not it! Try again.";
        return false;
    }

//           _
//      .__(.)< (MEOW)
//       \___)  

}

int main()
{
    srand(time(NULL));

    int LevelDifficulty = 1;
    int const MaxDifficulty = 10;

    while (LevelDifficulty <= MaxDifficulty) // Loop game until all levels are complete
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear(); // Clears any erros
        std::cin.ignore(); // Clears the buffer

        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
        
    }
    std::cout << "\n*** WooHoo you're home! Now go take a nap, you need it.";
    return 0;
}



Privacy & Terms