-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTripleX.cpp
89 lines (57 loc) · 2.08 KB
/
TripleX.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <string>
#include <ctime>
void PrintIntroduction (int Difficulty)
{
//print welcome messege and directions for players
std::cout << "\n\nYou are a secret agent breaking into level " << Difficulty;
std::cout << " secure server room...\n Enter the correct cofe to continue...\n\n";
}
bool PlayerGame(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 CodeProducts to the terminal
std::cout << std::endl;
std::cout << "+ There are 3 numbers in the code";
std::cout << "\n+ The code add-up to: " << CodeSum;
std::cout << "\n+ The code 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 players guess is correct
if (GuessSum == CodeSum && CodeProduct == GuessProduct)
{
std::cout <<"congrats, transfering to next level... "<< std::endl;
return true;
}
else
{
std::cout << "\nLoser! haha, try again!";
return false;
}
}
int main ()
{
srand(time(NULL)); //create new random sequene based on time of the day
int LevelDifficulty = 1;
const int MaxLevelOfDifficulty = 5;
while (LevelDifficulty <= MaxLevelOfDifficulty) // loop game untill all levels are reached
{
// std::cout << rand() % 3 << "\n";
bool bLevelComplete = PlayerGame(LevelDifficulty);
std::cin.clear(); //Clears any errors
std::cin.ignore(); // Discards the buffer
if (bLevelComplete){
++LevelDifficulty;
}
}
std::cout << "\n *** Congrats! you have completed all levels ***\n";
return 0;
}