#include <iostream>
int main()
{
// Print welcome messages to the terminal
std::cout << "You are a courier, hired by the Mojave Express, to deliver a package to the New Vegas Strip.";
std::cout << std::endl;
std::cout << "To deliver the package you must pass these number locks..." << std::endl;
// Declare 3 number code
const int CodeA = 4;
const int CodeB = 3;
const int CodeC = 2;
const int CodeSum = CodeA + CodeB + CodeC;
const int CodeProduct = CodeA * CodeB * CodeC;
// Print CodeSum and CodeProduct to the terminal
std::cout << std::endl;
std::cout << "+ There are 3 numbers in the lock" << std::endl;
std::cout << "+ The numbers add-up to: " << CodeSum << std::endl;
std::cout << "+ The numbers multiply to give: " << CodeProduct << std::endl;
int GuessA, GuessB, GuessC;
std::cin >> GuessA;
std::cin >> GuessB;
std::cin >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "You're in!";
}
else
{
std::cout << "Looks like where you're standing it must seem like an 18k run of bad luck.\nBut truth is, the game was rigged from the start. \n==========YOU LOSE==========";
}
return 0;
}
I finished it
#include <iostream>
#include <ctime>
void PrintIntroduction(int Difficulty)
{
// Print welcome messages to the terminal
std::cout << "\n\nYou are a courier, hired by the Mojave Express, to deliver a package to the New Vegas Strip.\n";
std::cout << "To deliver the package you must pass these level " << Difficulty;
std::cout << " number locks...\n\n";
}
bool PlayGame(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;
// Print CodeSum and CodeProduct to the terminal
std::cout << "+ There are 3 numbers in the lock";
std::cout << "\n+ The numbers add-up to: " << CodeSum;
std::cout << "\n+ The numbers multiply to give: " << CodeProduct << std::endl;
// Store player guess
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA + GuessB + GuessC;
int GuessProduct = GuessA * GuessB * GuessC;
// Check if the players guess is correct
if (GuessSum == CodeSum && GuessProduct == CodeProduct)
{
std::cout << "\nYou're in! ";
return true;
}
else
{
std::cout << "\nThat wasn't it, try again.";
return false;
}
}
int main()
{
srand(time(NULL)); // Creates new random sequence based on the time of day
int LevelDifficulty = 1;
int const MaxDifficulty = 5;
while (LevelDifficulty <= MaxDifficulty) // Loop game until all levels are completed
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear(); // Clears any errors
std::cin.ignore(); // Discards the buffer
if (bLevelComplete)
{
++LevelDifficulty; // Increases level difficulty if the answer was correct
}
}
std::cout << "\nLooks like where you're standing it must seem like an 18k run of good luck, you delivered the package!";
return 0;
}