-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrapsStat.cpp
More file actions
70 lines (58 loc) · 1.31 KB
/
crapsStat.cpp
File metadata and controls
70 lines (58 loc) · 1.31 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/****************************************
James Bertel
CS111
Lab 5-1
10-18-17
This program will calculate the probabilities of willing and losing in the craps game.
****************************************/
#include <iostream>
#include <cstdlib>
using namespace std;
int rollDice();
bool playGame();
int main()
{
srand(time(0));
int games;
cout << "How many games do you want to play?: ";
cin >> games;
??? = playGame();
????????????????????????????
return 0;
}
/*****************
This function plays one craps game.
It should return true if win or return false if lose
************/
bool playGame()
{
int roll = rollDice();
int firstRoll = rollDice();
cout << firstRoll << endl;
if(firstRoll==7||firstRoll==11)
game = true;
else if(firstRoll==2||firstRoll==3||firstRoll==12)
game = false;
else //firstRoll==1, 3-6, 8-10)
{
do
{
roll = rollDice();
cout << roll << endl;
}while(roll!=firstRoll&&roll!=7);
if(roll==firstRoll)
game = true;
if(roll==7)
game = false;
}
return game;
}
/******************************************
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;
}