#include<iostream>
#include<ctime>
void Printintroduction(int Difficulty)
{
std::cout<< "\nyou are a sectet agent breaking into a level " << Difficulty;
std::cout<< std::endl;
std::cout<< "secure server room....\nEnter the correct code to continue.....\n";
}
bool Playgame( int Difficulty)
{
Printintroduction(Difficulty);
//declare 3 number code
int CodeA = rand() % Difficulty + Difficulty;
int CodeB = rand() % Difficulty + Difficulty;
int CodeC = rand() % Difficulty + Difficulty;
int Codesum = CodeA + CodeB + CodeC;
int Codeprod = CodeA * CodeB * CodeC;
//print sum and product to the terminal
std::cout<< "\nThere are three numbers in the code\n";
std::cout<< "The code add up to give "<< Codesum;
std::cout<<"\nThe code multiply to give "<< Codeprod<<"\n";
// Store player guess
int GuessA, GuessB, GuessC ;
std::cin>> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProd = GuessA * GuessB * GuessC;
//Chech if the player guess is correct
if(GuessSum==Codesum && GuessProd==Codeprod)
{
std::cout<<"\nThats Correct!....! \n";
return true;
}
else
{
std::cout<< "\nYou lost here...!"<< " Try again... Agent!!\n";
return false;
}
}
int main()
{
srand(time(NULL));
int Leveldifficulty = 1;
int const Maxlevel = 5;
while (Leveldifficulty <= Maxlevel)
{
bool blevelcomplete = Playgame(Leveldifficulty);
std::cin.clear();
std::cin.ignore();
if (blevelcomplete)
{
++Leveldifficulty;
}
}
std::cout<< "You have reached maximum level you win!...\n";
return 0;
}
1 Like
Great game!