My version of TripleX

#include
#include

void PrintIntroduction(int Difficulty)
{
// Output to terminal the scenario
std::cout << “\n\nYou are a bomb diffuser who needs to diffuse a level " << Difficulty;
std::cout << " bomb before it blows everybody up.\n”;
std::cout << “You need to enter the correct codes to diffuse the bomb.\n\n”;
}

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

   // Declare variables a, b and c and assign values to them
// These values can't be changed
const int CodeA = rand()%Difficulty + Difficulty;
const int CodeB = rand()%Difficulty + Difficulty;
const int CodeC = rand()%Difficulty + Difficulty;

// Declare and assign variables with the sum and product of the previous variables
int CodeSum = CodeA + CodeB + CodeC;
int CodeProduct = CodeA * CodeB * CodeC;

// Output the sum and product
std::cout << "There are 3 numbers in the code\n";
std::cout << "The codes add up to " << CodeSum;
std::cout << "\n+ The product of the codes is " << 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 the player's guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
    std::cout << "\nYou guessed correctly! The bomb is diffused and everyone is safe!";
    std::cout << "\nMoving to the next level.";
    return true;
}
else
{
    std::cout << "\nYou guessed wrong and the bomb went off!";
    std::cout << "\nPlease try again.";
    return false;
}

}

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

int LevelDifficulty = 1;
const int MaxDifficulty = 5;

while (LevelDifficulty <= MaxDifficulty) // Loop until all levels are completed
{
    bool bLevelComplete = PlayGame(LevelDifficulty);
    std::cin.clear();
    std::cin.ignore();

    if (bLevelComplete)
    {
        ++LevelDifficulty;
    }
    
}

std::cout << "\nCongratulations! You have diffused all the bombs and completed the game!";
return 0;

}

1 Like

Looking good! :fire:

Privacy & Terms