Game of Craps

Hello everyone,
I am needing help on a game of Craps. Below is the code I have written, but when the player runs out of money and the game end it show the last stakes to be zero. I think the problem is in lines 76 and 77.

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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <ctime>
#include <stdlib.h>

using namespace std;

unsigned askForInititalStakeAmountFunc();
unsigned askForBetDonePlayingFunc     (unsigned stakeUns);
unsigned rollDemBonesFunc             (unsigned &rollCountUns);
void     evaluateRollFunc             (unsigned diceRollResultsUns, unsigned &rollCountUns, unsigned &stakeUns,          unsigned betUns);
unsigned pointRollDemBonesFunc        (unsigned pointUns,           unsigned &rollCountUns);

int _tmain(int argc, _TCHAR* argv[])
{
	int dummy;
	
	unsigned stakeUns = askForInititalStakeAmountFunc();
	unsigned betUns;
	unsigned rollCountUns = 0;
	unsigned diceRollResultsUns;
	
	//srand(time(NULL));
	srand((unsigned int)time(NULL));

	do {
		betUns = askForBetDonePlayingFunc(stakeUns);
		if (betUns != 0) {
			diceRollResultsUns = rollDemBonesFunc(rollCountUns);
			evaluateRollFunc(diceRollResultsUns, rollCountUns, stakeUns, betUns);
		}
} 
	while ( (betUns != 0) && (stakeUns !=0) );
	
	cout << endl << endl;
	
	if (betUns == 0)        cout << "Player ends Game:"        << endl;
	else stakeUns = 0;  
	cout << "Out of money, Game ends:" << endl;
	cout << "Roll Count         : " << rollCountUns<<endl;
	cout << "Final Stake Amount : " << stakeUns    <<endl;
	cout << endl; 
 
	
	cin >> dummy;
	
	return 0;

}

unsigned askForInititalStakeAmountFunc() 
{
	int initialAmount;
	cout << "Enter initial amount of money available to bet. " << endl;
	cin >> initialAmount;
	
	while (initialAmount <= 0)
	{
		cout << "Come back when you have some money. " << endl;
		cout << "Enter initial amount of money available to bet. " << endl;
		cin >> initialAmount;
	}
	cout << "You have " << initialAmount << " dollars in your account. " << endl;
	cout << endl;
	return initialAmount;
}

unsigned askForBetDonePlayingFunc     (unsigned stakeUns)
{
	int betAmount;
	cout << "How much do you want to bet? " << "If you want to quit playing enter 0." << endl;
	cout << endl;
	cin >> betAmount;
	
	while(true){
		if( betAmount > stakeUns)
	 
		{
		
		//while (betAmount == stakeUns)
		cout << "You must enter a correct amount. " << endl;
		cout << endl;
		cout << "How much do you want to bet? " << endl;
		cout << endl;
		cin >> betAmount;
		//if (betAmount ==0)
		
		//break;
		
		}
		
		
			return betAmount;
	}
}

unsigned rollDemBonesFunc             (unsigned &rollCountUns)
	{
	
	
		
	int dice = 0 , dice2 = 0, sum;
	dice = rand() % 6 + 1; 
	dice2 = rand() % 6 + 1;
	sum = dice + dice2;
 
	rollCountUns++;
	cout << "The sum of your roll is " << sum << "." " Your number of rolls is " << rollCountUns << "." << endl;  
	cout << "For your next roll "; system ("pause");
	cout << endl; 
	return sum;
	}

void     evaluateRollFunc             (unsigned diceRollResultsUns, unsigned &rollCountUns, unsigned &stakeUns,          unsigned betUns)

{
	
	if (diceRollResultsUns == 7 || diceRollResultsUns == 11)
		{
		stakeUns += betUns;
		cout << "You WON!!" << endl; 
		cout << endl;
	} 
	else if (diceRollResultsUns == 2 || diceRollResultsUns == 3 || diceRollResultsUns == 12)
		{
      
		stakeUns -= betUns;
		cout << "Sorry you LOST!!" << endl;
		cout << endl;
		} 
	else 
		{ 
		if (pointRollDemBonesFunc (diceRollResultsUns, rollCountUns)){
		cout << "You WON!!" << endl;
		cout << endl;
		stakeUns += betUns;
		}
	else	
		{
		
		
			cout << "Sorry you LOST!!" << endl;
			cout << endl;
		stakeUns -= betUns;
		
		
		}
	}
	
 cout << "You have " << stakeUns << " dollars in your account. " << endl;
 cout << endl;
}

unsigned pointRollDemBonesFunc  (unsigned pointUns, unsigned &rollCountUns)
{
	unsigned diceRoll;

	while (true)
	{
		diceRoll = rollDemBonesFunc (rollCountUns);

		if( diceRoll == pointUns) 
		{
			return 1;
		}
		else if (diceRoll ==7)
		{
		return 0;
		}
	}
}
Topic archived. No new replies allowed.