-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcraps.cpp
More file actions
53 lines (44 loc) · 1.03 KB
/
craps.cpp
File metadata and controls
53 lines (44 loc) · 1.03 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
/****************************************
James Bertel
CS111
Lab 5-1
10-18-17
This program will stimulate a game of craps.
****************************************/
#include <iostream>
#include <cstdlib>
using namespace std;
int rollDice();
int main()
{
srand(time(0));
int roll;
int firstRoll = rollDice();
cout << firstRoll << endl;
if(firstRoll==7||firstRoll==11)
cout << "==== WIN ====" << endl;
else if(firstRoll==2||firstRoll==3||firstRoll==12)
cout << "==== LOSE ====" << endl;
else //firstRoll==1, 3-6, 8-10)
{
do
{
roll = rollDice();
cout << roll << endl;
}while(roll!=firstRoll&&roll!=7);
if(roll==firstRoll)
cout << "==== WIN ====" << endl;
if(roll==7)
cout << "==== LOSE ====" << endl;
}
return 0;
}
/******************************************
This function simulates rolling a pair of dice.
It returns a random number between 2 and 12.
******************************************/
int rollDice()
{
int roll = (rand()%6 + 1)+(rand()%6 + 1);
return roll;
}