// 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; }