Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
BankHeistSimple/InitialDesign.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
75 lines (61 sloc)
1.96 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<string> | |
#include<ctime> | |
void PrintIntroduction(int Difficulty) { | |
std::cout << "\n\nYou are a secret agent breaking into a level " << Difficulty; | |
std::cout << " secure server room...\nEnter the correct code to continue....\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; | |
std::cout << "+ There are three numbers in the code"; | |
std::cout << "\n+ The code adds-up to: " << CodeSum; | |
std::cout << "\n+ The codes multiply to give: " << CodeProduct << std::endl; | |
int GuessA, GuessB, GuessC; | |
std::cin >> GuessA >> GuessB >> GuessC; | |
int GuessSum = GuessA + GuessB + GuessC; | |
int GuessProduct = GuessA * GuessB * GuessC; | |
if (GuessSum == CodeSum && GuessProduct == CodeProduct) | |
{ | |
std::cout << "\nYou win !"; | |
return true; | |
} | |
else | |
{ | |
std::cout << "\nYou messed up !"; | |
return false; | |
} | |
} | |
int main() | |
{ | |
int counter = 3; | |
int LevelDifficulty = 1; | |
const int MaxDifficulty = 5; | |
while (LevelDifficulty <= MaxDifficulty)// Loop game until game is completed | |
{ | |
bool bLevelComplete = PlayGame(LevelDifficulty); | |
std::cin.clear(); | |
std::cin.ignore(); | |
if (bLevelComplete) { | |
++LevelDifficulty; | |
} | |
else | |
{ | |
std::cout << " you have " << counter - 1 << " turns remaining" << std::endl; | |
counter = counter - 1; | |
if (counter == 0) { | |
std::cout << "The police is behind you and you have lost" << std::endl; | |
break; | |
} | |
} | |
} | |
if (counter != 0) { | |
std::cout << "Congrulations You have completed the game"; | |
return 0; | |
} | |
} | |