I need help with this program. I am new in Programming and I need to write this program asap. Thanks

hi
Last edited on
Whst do you need help with, and what have you written so far? We aren't exactly going to just do your homework for you, though we can help you fix specific problems that you may encounter.
g
Last edited on

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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include <iostream>
#include <iomanip>
#include <cstdlib> 
#include <ctime> 

using namespace std;

int Dice(int DV[], int Roll = 2);

void gameCraps(int sum, int Balance, int wager);

enum Status {CONTINUE, WON, LOST};

int main()
{
int sum, bAccount;
int DV[2];
int Balance = bAccount;
int wager;

srand(time(0));

sum = Dice(DV);
cout << " ____________ ________ _________ _________ _______ " <<endl;
cout << " / _____ / / ____ \\ / ____ | / _____ \\ / ____/" << endl;
cout << " / / / / / / / / / / | | / / / / / / " << endl;
cout << " / / / / / /___/ / / /_____| | / /____/ / / /___ " << endl;
cout << " / / /__/ / _____/ / ______ / / ________/ \\____ \\ " << endl;
cout << " / / __ / _ \\ / / / / / / \\ \\ " << endl;
cout << " / / / / / / \\ \\ / / / / / / / / " << endl;
cout << " / /_____/ / / / \\ \\ / / / / / / ______/ / " << endl;
cout << " /___________/ /__/ \\__\\ /__/ /__/ /__/ /________/ " << endl;




cout << "please create a Bank Acount" << endl;
cin >>bAccount;

cout << "\nYour bank balance is: " << "$" << bAccount << "\n";
cout << "Please enter a wager - ";

cin >> wager;
if (wager > bAccount)
{
cout << "Not valid" << endl;
cout << "Please enter a wager - " << endl;
cin >> wager;
}
cout << "\n" << "Your wager: " << "$" << wager << "\n\n";
cout << "Player rolled: " << DV[0] << " + " << DV[1] << endl;

gameCraps(sum, Balance, wager);

return 0;
}

int Dice(int DV[], int Roll)
{
int dicevalues = 0;

for(int i = 0; i < Roll; i++)
{
DV[i] = 1 + rand()%6;
}
for(int i = 0; i < Roll; i++)
{
dicevalues = dicevalues + DV[i];
}
return dicevalues;
}

void gameCraps(int sum, int Balance, int wager)
{
int Point;
int DV[2];
char userchoice;
Status gameStatus;

switch(sum)
{
case 7:
gameStatus = WON;
case 11:
gameStatus = WON;
break;
case 2:
gameStatus = LOST;
case 3:
gameStatus = LOST;
case 12:
gameStatus = LOST;
break;
default:
gameStatus = CONTINUE;
Point = sum;
cout << "Point is: " << Point << endl;
break;
}
if(sum==WON)
cout << "player wins" <<endl;
else
cout << " player loses " << endl;

while (gameStatus == CONTINUE)
{
sum = Dice(DV);
cout << "Player rolled: " << DV[0] << " + " << DV[1] << endl;

if (sum == Point)
{
gameStatus = WON;
}
else if (sum == 7)
{
gameStatus = LOST;
}

if (gameStatus == WON)
{
cout << "\n\t***Player wins***\n" << endl;
Balance = Balance + wager;
cout << "Your bank balance is now: " << "$" << Balance << "\n";
cout << "Would you like to continue or cash out?" << endl;
cout << "select 'Y' to continue . select 'N' to cash out\n" << endl;
cin >> userchoice;

if (userchoice == 'y')
{
cout << "Good luck!!\n";
gameStatus = CONTINUE;
}
while (gameStatus == CONTINUE)
{
sum = Dice(DV);

cout << "Your bank balance is: " << "$" << Balance << "\n";
cout << "Please enter a wager - ";

cin >> wager;

cout << "\n" << "Your wager: " << "$" << wager << "\n\n";
cout << "Player rolled: " << DV[0] << " + " << DV[1] << endl;

gameCraps(sum, Balance, wager);
}
if (userchoice == 'n')
{
cout << "You go away with a bank balance of " << "$" << Balance << "\n";
exit(0);
}
if (userchoice !='n' || userchoice !='y')
{
cout << "Please enter a valid choice ('Y' or 'N')\n";
exit(-1);
}
}
else
{
cout << "\n\t***Player loses***\n" << endl;
Balance = Balance - wager;
if (Balance <= 0)
{
cout << "Sorry, you don't have enough cash to continue! Please try again.\n";
cout << "Your bank balance is now " << "$" << Balance << "\n";
exit(-1);
}
if (Balance > 0 )
{
cout << "Would you like to continue or cash out?" << endl;
cout << "select 'Y' to continue . select 'N' to cash out\n" << endl;
cin >> userchoice;
if (userchoice == 'y')
{
cout << "Good luck my friend!!!\n";
gameStatus = CONTINUE;
}
while (gameStatus == CONTINUE)
{
sum = Dice(DV);

cout << "Your bank balance is: " << "€" << Balance << "\n";
cout << "Please enter a wager - ";

cin >> wager;

cout << "\n" << "Your wager: " << "$" << wager << "\n\n";
cout << "Player rolled: " << DV[0] << " + " << DV[1] << endl;

gameCraps(sum, Balance, wager);
}
if (userchoice == 'n')
{
cout << "Thanks for playing! You go away with a balance of " << "$" << Balance;
exit(0);
}
if (userchoice !='y' || userchoice !='n')
{
cout << "Please enter a valid choice to continue\n";
exit(-1);
}
}
}
}
}
Sorry, I don't know how to make it to read like what it is in source file.

Can someone help me with this program please?
Here are the rules:

* If player roll 7 or 11 on the first roll, they win, if s/he roll 2, 3, or 12, they lose.

* If a player does not win or lose on the first roll, that total establishes the "point".

*The player then continues to roll until, the "point" is rolled, in which case he wins or a 7 is rolled, in which case he loses. There is no limit on the number of subsequent rolls. Just keep rolling until a 7 or the "point" is rolled.

*If the player's point is an even number (4, 6, 8, 10) ask if he wants to bet the "hard way". If so, prompt for bet. The "hard way" is a one roll bet that pays double the wager if he gets his points with a pair.

* Once a player wins or loses, that is a game and it all starts over unless he wants to cash out.

*
First question. How is it when you create the bank account you are couting Balance ?

1
2
3
4
5
cout << "please create a Bank Acount" << endl;
cin >>bAccount;

cout << "\nYour bank balance is: " << "$" << bAccount << "\n";
cout << "Please enter a wager - ";


This is gonna cout your bank account not the balance
Well, it suppose to be one of them. either balance or bank account. I think I messed up somewhere. What I am trying to do is have a bank account or balance at the beginning, when the player wins, add points to his/her account, when they lose subtract it from account/balance, and when they want to cash out, it should say how much money they have to go away with. But the other problem I don't know how to start with is when the player wants to play "hard way".

Thank you
Topic archived. No new replies allowed.