My TrapleX code so far with Level Difficulty

#include <iostream>

void PrintIntroduction(int Difficulty)
{
//Print Welcome messages to the terminal
    std::cout << "\n\nYou are a secret agent breaking into a level " << Difficulty;
    std::cout << " secure server room \nEnter the correct codes to continue.. \n\n";


}
bool PlayGame(int Difficulty)
{
    PrintIntroduction(Difficulty);
    
    // Declare 3 number code
    const int CodeA = 4;
    const int CodeB = 3;
    const int CodeC = 2;

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

    // Print CodeSum and CodeProduct to the terminal
    std::cout << std::endl;
    std::cout << "* There are 3 numbers in the code"; 
    std::cout << "\n* The codes add-up to: " << CodeSum;
    std::cout << "\n* The codes multiply to give: " << 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
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "\nYou win!";
        return true;
    }
    else
    {
        std::cout << "\n You lose!";
        return false;
    }
}

int main() 
{
    int LevelDifficulty = 1;  
    int const MaxDifficulty = 5;

    while (LevelDifficulty <= MaxDifficulty) // Loop game until all levels completed
    {
        bool bLevelComplete = PlayGame(LevelDifficulty);
        std::cin.clear(); // Clear any errors.
        std::cin.ignore();// Discard the buffer.
    
        if (bLevelComplete)
        {
            ++LevelDifficulty;
        }
        
    }

    
   return 0;
}
1 Like

Looks really good!

Thanks…

Privacy & Terms