This repository has been archived by the owner on Oct 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathCricket_game.cpp
80 lines (67 loc) · 1.72 KB
/
Cricket_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
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
// Driver Code
int main()
{
int totalrun = 0;
srand(time(0));
int i;
// Generate a random number
// and store in variable
i = (rand() % 25) + 1;
cout << "~~~~~~~~ CRICKET GAME ~~~"
<< "~~~~~~~" << endl;
// Displaying the winning score
cout << "Your winning score "
<< i << "\n";
// while loop for true condition
while (1)
{
int player = 0;
int a;
if (totalrun > i)
{
cout << "you won your score="
<< totalrun << "\n";
// To exit loop
exit(0);
}
else
{
// Generate random no. and
// store in a variable
a = (rand() % 6) + 1;
cout << "Enter no. between "
<< "1 to 6" << endl;
// Taking input from user
// to score runs
cin >> player;
// Checking if user's score
// exceeds the winning score
// Displaying random number
// taken by system on screen
cout << "System: " << a << endl;
// Check if number inserted
// by user is the same random
// number generated by system
// inside loop
if (player == a)
{
cout << "OUT your score ="
<< totalrun
<< endl;
// To exit loop
exit(0);
}
// Storing total runs scored
// by user
else
{
totalrun = totalrun + player;
}
}
}
return 0;
}