Triple X Final

#include

#include

void PrintIntroduction (int Difficulty)

{

// Back Story (Expression Statements)

std:: cout << "\n\nYou are trying to hack into a Level " << Difficulty;

std:: cout << " server \nGet the numbers correct to get in...\n";

}

bool PlayGame(int Difficulty)

{

PrintIntroduction(Difficulty);

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

// Printing Sum and Product

std:: cout  << "There are three numbers in the code\n";

std:: cout  <<"*When you add these numbers, you get ";

std:: cout  << CodeSum <<"*\n";

std:: cout  << "*When you multiply these numbers, you get ";

std:: cout  << CodeProduct<< "*\n\n";

//Showing User Input

int GuessA, GuessB, GuessC;

std:: cin >> GuessA >> GuessB >> GuessC;

int GuessSum = GuessA + GuessB + GuessC;

int GuessProduct = GuessA * GuessB * GuessC;



//Showing if User is Right or Wrong

if (GuessSum==CodeSum && GuessProduct == CodeProduct)

{

    std:: cout << "Nice Job, On to the next Level!";

    return true;

}

else

{

    std:: cout <<"Oh, that's not quite right. Try again";

    return false;

}

}

int main()

{

srand(time(NULL));  // creates random numbers based on the time of the day it is

int LevelDifficulty = 1;

int const MaxDifficulty = 5;

while (LevelDifficulty <= MaxDifficulty) // Looping Game until game hits the max level

{

bool bLevelComplete = PlayGame(LevelDifficulty);

std::cin.clear();// Clears all the errors

std::cin.ignore(); // Discards the buffer

if (bLevelComplete)

{

   ++LevelDifficulty;

}

}

std::cout << "\n Congratulations, You have successfully infiltrated the Servers!";

return 0;

}

1 Like

Everything looks good! Great job :clap:

Privacy & Terms