-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
122 lines (78 loc) Β· 1.88 KB
/
main.cpp
File metadata and controls
122 lines (78 loc) Β· 1.88 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <vector>
#include <random>
#include <cstdlib>
int guessGameLogic();
int userinput() {
int userVlue{};
std::cout <<"\033[33m" << "Enter Value-";
std::cin >> userVlue;
return userVlue;
}
int randomValueGenrator() {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distrib(1, 100);
return distrib(gen);
}
bool comparisionRandomeAndUserInput(int x , int y) {
if (x == y) {
std::cout << "\033[34m" << "YOUWON\n";
return 1;
}
else if (x<y) {
std::cout<< "\033[31m" << "ValueIsSmall" <<'\n';
return 0;
}
else if (x>y) {
std::cout<<"\033[36m" << "ValueIsBig" << '\n';
return 0;
}
else {
}
}
bool wantToPlayLoop() {
int x{1};
int higestScore{};
system("cls");
while (x==1) {
system("cls");
int CurrentScore{ guessGameLogic() };
if (CurrentScore > higestScore) {
higestScore = CurrentScore+1;
}
std::cout << "HIGHEST SCORE-" << higestScore;
std::cout << "\nWant To Play More(1-Yes/0-No)-";
std::cin >> x;
}
return 0;
}
int guessGameLogic() {
system("cls");
std::cout << " \033[32m" << "GAME(BBX) (Guess Number B/W (1to100)) In The End Get Your Score Out Of 20(As lower As Better)" << '\n';
int userScore{ 19 };
int randomValue{ randomValueGenrator() };
bool isGuss{ false };
while (isGuss == false) {
int usercurrectval{ userinput() };
system("cls");
isGuss = comparisionRandomeAndUserInput(usercurrectval, randomValue);
std::cout << "\033[35m" << "Currect Score-" << userScore << '\n';
userScore--;
if (userScore < 0) { // why not <= casue of that it was giving error of ending at 1 not 0
for (int i = 0; i <= 10; i++) {
std::cout << "You Lost\n";
}
return 0;
}
}
system("cls");
std::cout << "Your Score-" << userScore + 1 << '\n';
std::cout << "DONE!";
return userScore;
}
int main()
{
wantToPlayLoop();
return 0;
}