BLACKJACK

Hi ive been trying to write this blackjack game and i got stuck what im trying to do is make it so i can bet after each roll but im confused on how to do so..heres my code


# include <iostream>
# include <cmath>
# include <iomanip>
# include <cstdlib>
using namespace std;
int main()
{
int die1;
int die2;
int dice;
int bet;
int point;
int money = 100;
char roll;

do
{
cout << "You currently have $" << money << " on hand.";

cout << "\nPlace your bet (minimum $1): ";
cin >> bet;

while (bet < 1 || bet > money)
{
if (bet < 1)
cout << "\nC'mon, take a chance!";
if (bet > money)
cout << "\nYou don't have that much!";
cout << "\n\nPlace your bet (minimum $1): ";
cin >> bet;
}

cout << "\nYou bet $" << bet << ".";

cout << "\n\nPress ENTER to roll the dice.";
cin.get(roll);

die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
dice = die1 + die2;

cout << "\nYou rolled a " << die1 << " and a " << die2
<< " for a total of " << dice << ".";

if (dice == 7 )
{
cout << "Youve won";
money += bet;
}
cout <<money<<endl;

if (dice == 11)
{
cout << "Youve lost";
money -= bet;
}

else
{

cout << "\n\nPress ENTER to roll the dice.";
do
{
cin.get(roll);

die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
dice = die1 + die2;

cout << "\nYou rolled a " << die1
<< " and a " << die2
<< " for a total of " << dice << ".";

if (dice == 7)
{
cout << "youve won";
money += bet;
}

if (dice == 11)
{
cout << "youve lost";
money -= bet;
}

else
{
cout << "\nKeep rolling until you get a 7. "
<< "\nPress ENTER to roll the dice.";
}
cout <<money;
} while (dice != point || dice != 7);
}
} while (money > 0);

cout << "/nLooks like you ran out of money. "
<< "Thanks for playing!" << endl;




system("pause");
}
Well, the game you are making is actually called 'craps.' Anyway, you can basically just copy the loop that you have for betting the first time into the do loop, moving the "Press Enter to roll the dice" into there too:

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
# include <iostream>
# include <cmath>
# include <iomanip>
# include <cstdlib>
using namespace std;
int main()
{
int die1;
int die2;
int dice;
int bet;
int point;
int money = 100;
char roll;

do
{
cout << "You currently have $" << money << " on hand.";

cout << "\nPlace your bet (minimum $1): ";
cin >> bet;

while (bet < 1 || bet > money)
{
if (bet < 1)
cout << "\nC'mon, take a chance!";
if (bet > money)
cout << "\nYou don't have that much!";
cout << "\n\nPlace your bet (minimum $1): ";
cin >> bet;
}

cout << "\nYou bet $" << bet << ".";

cout << "\n\nPress ENTER to roll the dice.";
cin.get(roll);

die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
dice = die1 + die2;

cout << "\nYou rolled a " << die1 << " and a " << die2
<< " for a total of " << dice << ".";

if (dice == 7 )
{
cout << "Youve won";
money += bet;
}
cout <<money<<endl;

if (dice == 11)
{
cout << "Youve lost";
money -= bet;
}

else
{
do
{
cout << "You currently have $" << money << " on hand."; //copied the betting loop you had
cout << "\nPlace your bet (minimum $1): ";
cin >> bet;
while (bet < 1 || bet > money)
{
if (bet < 1)
cout << "\nC'mon, take a chance!";
if (bet > money)
cout << "\nYou don't have that much!";
cout << "\n\nPlace your bet (minimum $1): ";
cin >> bet;
}
cout << "\nYou bet $" << bet << "."; //end betting loop
cout << "\n\nPress ENTER to roll the dice."; //moved this down
cin.get(roll);

die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
dice = die1 + die2;

cout << "\nYou rolled a " << die1
<< " and a " << die2
<< " for a total of " << dice << ".";

if (dice == 7)
{
cout << "youve won";
money += bet;
}

if (dice == 11)
{
cout << "youve lost";
money -= bet;
}

else
{
cout << "\nKeep rolling until you get a 7. "
<< "\nPress ENTER to roll the dice.";
}
cout <<money;
} while (dice != point || dice != 7);
}
} while (money > 0);

cout << "/nLooks like you ran out of money. "
<< "Thanks for playing!" << endl;




system("pause");
}
Last edited on
Topic archived. No new replies allowed.