/
craps.cc
71 lines (57 loc) · 1.13 KB
/
craps.cc
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
#include <iostream>
#include <stdlib.h>
using namespace std;
int roll()
{
srand(time(NULL));
int r = (1 + rand() % 6) + (1 + rand() % 6);
return r;
}
int main()
{
int win = 0;
int lose = 0;
cout << "Press enter to roll: ";
cin.get(); //moves on to next line when Enter key pressed
int firstroll = roll();
cout << "First roll: " << firstroll << endl;
if(firstroll == 7 || firstroll == 11)
{
win += 1;
cout << firstroll << ", you win" << endl;
}
else if(firstroll == 2 || firstroll == 3 || firstroll == 12)
{
lose += 1;
cout << firstroll << ", you lose" << endl;
}
else
{
int mark = firstroll;
cout << mark << " is your mark." << endl;
bool seven = false;
bool same = false;
while((seven == false) && (same == false))
{
cout << "Press enter to roll again: ";
cin.get();
int nextroll = roll();
if(nextroll == mark)
{
win += 1;
cout << nextroll << ", you win" << endl;
same = true;
}
else if(nextroll == 7)
{
lose += 1;
cout << nextroll << ", you lose" << endl;
seven = true;
}
else
{
cout << nextroll << ", roll again" << endl;
}
}
}
}