-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakes and Ladders..cpp
56 lines (54 loc) · 1.07 KB
/
Snakes and Ladders..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
#include<iostream>
#include<cstdlib>
#include<ctime>
#include <conio.h>
using namespace std;
int main()
{
int n1, n2, sum1 = 0, sum2 = 0;
srand(time(0));
for (int i = 1; i <= 50; i++)
{
cout << "!!! PLAYER 1 !!!" << endl;
cin.get();
if (sum1 < 21)
{
n1 = rand() % 6 + 1;
cout << "Player 1's : " << n1 << endl;
sum1 = sum1 + n1;
if (sum1 > 20)
{
sum1 = sum1 - n1;
}
cout << "Player 1's total points : " << sum1 << endl;
if (sum1 == 20)
{
cout << endl;
cout << "!!!!!! Player 1 wins the game !!!!!!"<<endl;
break;
}
}
cout << endl;
cout << "!!! PLAYER 2 !!!"<<endl;
cin.get();
if (sum2 < 21)
{
n2 = rand() % 6 + 1;
cout << "Player 2's : " << n2 << endl;
sum2 = sum2 + n2;
if (sum2 > 20)
{
sum2 = sum2 - n2;
}
cout << "Player 2's total points : " << sum2 << endl;
if (sum2 == 20)
{
cout << endl;
cout << "!!!!!! Player 2 wins the game !!!!!!"<<endl;
break;
}
}
cout << endl;
}
return 0;
}