-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumber Guessing game.cpp
156 lines (154 loc) · 4.16 KB
/
Number Guessing game.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
void difficult()
{
srand(time(0));
int secret_Number = 1 + (rand() % 100);
int player_Choice;
cout << "\nYou have 5 choices for finding the secret number between 1 to 100.";
int choices_Left = 5;
for (int i = 1; i <= 5; i++)
{
cout << "\n\nEnter the number:";
cin >> player_Choice;
if (player_Choice == secret_Number)
{
cout << "\n\nWell played! You won, "<< player_Choice<< " is the secret number\n";
cout << "\t\t\t Thanks for playing....\n";
cout << "\nPlay the game again with us!!\n\n\n";
break;
}
else
{
cout << "\nOops, "<< player_Choice<< " is not the right number\n";
if (player_Choice > secret_Number)
{
cout << "The secret number is smaller than the number you have chosen \n";
}
else
{
cout << "The secret number is greater than the number you have chosen \n";
}
choices_Left--;
cout << choices_Left << " choices left. \n";
if (choices_Left == 0)
{
cout << "You couldn't find the secret number, it was"<< secret_Number<< ", You lose!!\n\n";
cout << "Play the game again to win!!!\n\n";
}
}
}
}
void medium()
{
srand(time(0));
int secret_Number = 1 + (rand() % 100);
int player_Choice;
cout << "\nYou have 7 choices for finding the secret number between 1 to 100.";
int choices_Left = 7;
for (int i = 1; i <= 7; i++)
{
cout << "\n\nEnter the number: ";
cin >> player_Choice;
if (player_Choice == secret_Number)
{
cout << "\n\nWell played! You won, "<< player_Choice<< " is the secret number\n";
cout << "\t\t\t Thanks for playing....\n";
cout << "Play the game again with us!!\n\n\n";
break;
}
else
{
cout << "\nOops, " << player_Choice<< " is not the right number\n";
if (player_Choice > secret_Number)
{
cout << "The secret number is smaller than the number you have chosen \n";
}
else
{
cout << "The secret number is greater than the number you have chosen \n";
}
choices_Left--;
cout << choices_Left << " choices left. \n";
if (choices_Left == 0)
{
cout << "You couldn't find the secret number, it was"<< secret_Number<< ", You lose!!\n\n";
cout << "Play the game again to win!!!\n\n";
}
}
}
}
void easy()
{
srand(time(0));
int secret_Number = 1 + (rand() % 100);
int player_Choice;
cout << "\nYou have 10 choices for finding the secret number between 1 to 100.";
int choices_Left = 10;
for (int i = 1; i <= 10; i++)
{
cout << "\n\nEnter the number:";
cin >> player_Choice;
if (player_Choice == secret_Number)
{
cout << "\n\nWell played! You won, "<< player_Choice<< " is the secret number\n";
cout << "\t\t\t Thanks for playing....\n";
cout << "Play the game again with us!!\n\n\n ";
break;
}
else
{
cout << "\nOops, " << player_Choice<< " is not the right number\n";
if (player_Choice > secret_Number)
{
cout << "The secret number is smaller than the number you have chosen\n";
}
else
{
cout << "The secret number is greater than the number you have chosen \n";
}
choices_Left--;
cout << choices_Left << " choices left. \n";
if (choices_Left == 0)
{
cout << "You couldn't find the secret number, it was"<< secret_Number<< ", You lose!!\n\n";
cout << "Play the game again to win!!!\n\n";
}
}
}
}
int main()
{
int Choice;
cout << "\n\n\t\t\t\t\t \t\t\t\tWelcome to Guess The Number Game...!\n";
cout << "\n \tYou have to guess a number between 1 to 100. ";
cout << "\n \tYou'll have limited choices based on the level you choose.";
cout << "\n \t\t\t\t\t\t\t\t\t\tGood Luck!\n\n";
do
{
cout << "\n Level: \n\n";
cout << "1 For easy\n";
cout << "2 For medium\n";
cout << "3 For difficult\n";
cout << "0 For ending the game\n\n\n";
cout << "Choose Level: ";
cin >>Choice;
switch(Choice)
{
case 1: easy();
break;
case 2:
medium();
break;
case 3:
difficult();
break;
case 0:
exit(0);
break;
}
}while(Choice<5);
return 0;
}