# Complete TripleX Code

``````#include<iostream>
#include<time.h>

void PrintIntroduction(int Difficulty)
{
// Print welcome message
std::cout << "\nWelcome to Sejong's guessing game! The difficulty is " << Difficulty << ".";
std::cout << "\nYou need to enter the right three numbers in any sequence to continue...\n";
}

bool PlayGame(int Difficulty, int Range)
{
PrintIntroduction(Difficulty);

// Generate three numbers between 1 and range
const int CodeFirst = rand() % Range + 1;
const int CodeSecond = rand() % Range + 1;
const int CodeThird = rand() % Range + 1;

// Find the sum and product of three numbers
const int CodeSum = CodeFirst + CodeSecond + CodeThird;
const int CodeProduct = CodeFirst * CodeSecond * CodeThird;
std::cout << "\n+The range is: 1 to " << Range;
std::cout << "\n+The numbers add up to: " << CodeSum;
std::cout << "\n+The numbers multiply to make: " << CodeProduct << std::endl;

// Get guesses from player
int GuessFirst;
int GuessSecond;
int GuessThird;

std::cout << "\nEnter your first number... ";
std::cin >> GuessFirst;
std::cout << "Enter your second number... ";
std::cin >> GuessSecond;
std::cout << "Enter your third number... ";
std::cin >> GuessThird;

// Find sum and products of guesses
const int GuessSum = GuessFirst + GuessSecond + GuessThird;
const int GuessProduct = GuessFirst * GuessSecond * GuessThird;

// Tell player if guess is correct
if(GuessSum == CodeSum && GuessProduct == CodeProduct){
std::cout << "\nThat's right!\n";
return true;
}
else
{
std::cout << "\nSorry, that's not right. Try again.\n";
return false;
}
}

int main()
{
// Set inital and maximum difficulty
int LevelDifficulty = 1;
const int MaxDifficulty = 3;

// Initialize random seed
srand (time(NULL));

// Generate range of numbers
int MaxRange = 3;

while(LevelDifficulty <= MaxDifficulty)
{
bool bLevelComplete = PlayGame(LevelDifficulty, MaxRange);
std::cin.clear();
std::cin.ignore();

if (bLevelComplete)
{
/* Increase difficulty and add 3 to range of numbers
Numbers beyond 9 are too difficult for game so add accordingly to
maximum difficulty*/
++LevelDifficulty;
MaxRange = MaxRange + 3;

}
else
{
// Restart Level Difficulty
LevelDifficulty = 1;
}

}

std::cout << "\nCongrats! You won!\n";
return 0;
}
``````