-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
67 lines (53 loc) · 1.53 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <ctime>
using namespace std;
void PrintIntro( int LevelDifficulty )
{
std:: cout << "\n\nYou are a secret agent breaking into a level " << LevelDifficulty;
std:: cout << " secure server room\nYou will need to enter the correct codes to continue\n\n";
}
bool PlayGame(int DifficultyLevel)
{
PrintIntro(DifficultyLevel);
const int CodeA = rand() % DifficultyLevel + DifficultyLevel;
const int CodeB = rand() % DifficultyLevel + DifficultyLevel;
const int CodeC = rand() % DifficultyLevel + DifficultyLevel;
const int sum = CodeA+CodeB+CodeC;
const int product = CodeA*CodeB*CodeC;
std::cout << "Each code will have three numbers\n";
std::cout << "The sum of the codes is: " << sum;
std::cout << "\nThe product of the codes is: " << product <<std::endl;
int GuessA, GuessB, GuessC;
std::cin >> GuessA >> GuessB >> GuessC;
int GuessSum = GuessA+GuessB+GuessC;
int GuessProd = GuessA*GuessB*GuessC;
int AlertLevel = 1;
if (GuessSum == sum && GuessProd == product)
{
std::cout << "\nYou guessed correctly! ;D";
return true;
}
else {
std::cout << "\nYou guessed incorrectly! :'(";
++AlertLevel
return false;
}
}
int main()
{
srand(time(NULL));
const int MaxDifficulty = 10;
int LevelDifficulty = 1;
while (LevelDifficulty <= MaxDifficulty)
{
bool bLevelComplete = PlayGame(LevelDifficulty);
std::cin.clear();
std::cin.ignore();
if (bLevelComplete)
{
++LevelDifficulty;
}
};
std::cout << "\n Great work! All levels have been cracked";
return 0;
}