From 628904eb618e7349fac81d6415f275459b2600dc Mon Sep 17 00:00:00 2001 From: The-Tysonator Date: Sun, 23 Apr 2023 10:44:09 +0100 Subject: [PATCH] initial commit --- .gitignore | 1 + TripleX.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 .gitignore create mode 100755 TripleX.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b7ff13a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_STORE \ No newline at end of file diff --git a/TripleX.cpp b/TripleX.cpp new file mode 100755 index 0000000..0a7d3a6 --- /dev/null +++ b/TripleX.cpp @@ -0,0 +1,62 @@ +// Imports +#include +#include + +// Print Introduction +void PrintIntroduction(int Difficulty) { + // Welcome Message + std::cout << "You are a secret agent trying to break into a secure server room. Crack the level " << Difficulty - 1 << " code to continue.\n\n"; +} + +// Play Game +bool PlayGame(int Difficulty) { + // Welcome Message + PrintIntroduction(Difficulty); + // Generate Secret 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; + // Display Information + std::cout << "There are three numbers in the code.\nThe digits in the code add up to " << CodeSum << ".\nThe digits in the code multiply to give " << CodeProduct << ".\n\n"; + // Input + int GuessA, GuessB, GuessC; + std::cin >> GuessA; + std::cin >> GuessB; + std::cin >> GuessC; + std::cout << std::endl; + // Check Guess + int GuessSum = GuessA + GuessB + GuessC; + int GuessProduct = GuessA * GuessB * GuessC; + if (GuessSum == CodeSum && GuessProduct == CodeProduct) { + std::cout << "Code accepted.\n\n"; + return true; + } else { + std::cout << "Code rejected.\n\n"; + return false; + } +} + +// Main Function +int main() { + // Dificulty Settings + int LevelDifficulty = 2; + const int MaxDifficulty = 6; + srand(time(NULL)); + // Game Loop + while (LevelDifficulty <= MaxDifficulty) { + // Run Game + bool bLevelComplete = PlayGame(LevelDifficulty); + // Clear Errors and Discard The Buffer + std::cin.clear(); + std::cin.ignore(); + // Check Level + if (bLevelComplete) { + // Increment Difficulty + ++LevelDifficulty; + } + } + // Return + return 0; +} \ No newline at end of file