Here’s my code
#include <iostream>
#include <ctime>
int Lives = 3;
void PrintIntroduction(int Difficulty)
{
// Prints welcome messages to the terminal
std::cout << " _____ _ _ __ __\n";
std::cout << "|_ _| (_) | | \\ \\ / /\n";
std::cout << " | |_ __ _ _ __ | | ___ \\ V /\n";
std::cout << " | | '__| | '_ \\| |/ _ \\/ \\\n";
std::cout << " | | | | | |_) | | __/ /^\\ \\\n";
std::cout << " \\_/_| |_| .__/|_|\\___\\/ \\/\n";
std::cout << " | | \n";
std::cout << " |_| ";
std::cout << "\n\n===========================================================\n";
std::cout << "You are a secret agent breaking into a LEVEL " << Difficulty << " secure server room\n";
std::cout << "You need to enter the correct codes to continue...\n";
std::cout << "===========================================================\n";
}
bool bPlayGame(int Difficulty)
{
PrintIntroduction(Difficulty);
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;
// Prints sum and welcome to the terminal
std::cout << "Attempts Left: " << Lives << std::endl;
std::cout << "+ There are 3 numbers in the code";
std::cout << "\n+ The codes add-up to: " << CodeSum;
std::cout << "\n+ The numbers multiply to give: " << CodeProduct << std::endl;
// Stores player's guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
// Checks if the player's guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\n== Well done agent! You have extracted a file! Keep going! ==\n";
return true;
}
else
{
std::cout << "\n== You entered the wrong code! Careful agent! Try again ==\n";
Lives = Lives - 1;
return false;
}
}
int main()
{
srand(time(NULL));
int LevelDifficulty = 1;
const int MaxDifficulty = 5;
while (LevelDifficulty <= MaxDifficulty)
{
if (Lives >= 0)
{
bool bLevelComplete = bPlayGame(LevelDifficulty);
std::cin.clear();
std::cin.ignore();
if (bLevelComplete == true)
{
++LevelDifficulty;
}
}
else
{
std::cout << "\n======== Game Over ========";
break;
}
}
if (Lives > 0)
{
std::cout << "\n== Well done agent, you have extracted all of the files! Now, get out of there! ==";
}
return 0;
}```