C++ 3 dice rolls with only 1 int?

I'm doing a project of a crown and anchor game where you basically bet on a side of a dice and if you guess correctly you win or vice versa. I've done most of the program except I just need a few thing I don't know how to do. I was restricted to only using one int variable for a dice, but I have to throw 3 instead of one.
My program is as follow:

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
  #include<iostream> 
#include<cstdlib> 
#include<time.h> 
#include<string> 

using namespace std; 

int getRandomNum(int lowRange, int highRange); 

int main() 
{	
int totalMoney; // The amount of $ you have. 
int money;	 // Amount of $ you'll bet. 
int rollChoice; // Choice of your roll. 
int diceRoll;	 // Actual dice roll. 



srand( static_cast<int>( time(NULL) ) ); 

cout << "Welcome to the Crown and Anchor Game!" << endl; 
cout << "Good Luck!!!!!" << endl; 
cout << "How much money will you play with? $";	
cin >> totalMoney; 
cout << endl; 


cout << "***************************************... << endl << endl; 


cout << "Enter your bet $";	
cin >> money; 
while (money > totalMoney)	
{ 
cout << "Please bet $" << totalMoney << " or lower." << endl; 
cout << "Enter your bet $"; 
cin >> money; 
} 
cout << "Choose a character. Enter: " << endl;	
cout << "	1 for Heart" << endl;	
cout << "	2 for Crown" << endl; 
cout << "	3 for Diamond" << endl; 
cout << "	4 for Club" << endl; 
cout << "	5 for Anchor" << endl; 
cout << "	6 for Spade" << endl; 
cout << "...Your Choice: "; 
cin >> rollChoice; 

while (!(rollChoice < 7 && rollChoice > 0))	
{	
cout << endl; 
cout << "Please enter a valid character...." << endl << endl; 
cout << "...Your Choice: "; 
cin >> rollChoice; 
} 
cout << endl; 

diceRoll = getRandomNum(1, 6);	
cout << "Dice rolled: ";	
switch (diceRoll) 
{ 
case 1: 
{	
cout << "Heart"; 
break; 
} 
case 2: 
{ 
cout << "Crown"; 
break; 
} 
case 3: 
{ 
cout << "Diamond"; 
break; 
} 
case 4: 
{ 
cout << "Club"; 
break; 
} 
case 5: 
{ 
cout << "Anchor"; 
break; 
} 
default: 
{ 
cout << "Spade"; 
break; 
} 
} 
cout << endl << endl; 

if (rollChoice == diceRoll)	
{	
cout << "You won $" << money*2 << endl;	
cout << "Your current balance is $" << totalMoney + money*2 << endl; 
} 
else 
{ 
cout << "You lost $" << money << endl; 
cout << "Your current balance is $" << totalMoney - money << endl; 
} 


} 

int getRandomNum(int lowRange, int highRange) 
{ 
int randNum; 

randNum = ( rand() % (highRange - lowRange + 1) ) + lowRange; 

return randNum; 
}  


Right now I only have the game set up to roll 1 die, but how would I do it to allow 3 dices to roll without having 3 int variables for dice rolls? Also, I need to include whether the user wants to quit the game or not and if the user loses all his money, he loses the game.

Any help is appreciated, thanks.

Notice, I don't know if I did the math right when winning or losing money. Sorry. Also, I don't know if I'm missing some things.
Boolean value to decide whether or not the player won, do the roll three times the same way you did it before.

Subtract or add money as you need after you find out whether or not the player won.

When the current amount of money is 0, the game is over.
The thing is that I don't know how to include the rolling three times dice. How and where do I write the code down? I'm confused in that aspect. The same goes with ending the game or keep the loop going if the player chooses to keep playing.
1
2
3
4
for(int  x = 0; x < 3; x++)
{
    //dice roll code
}


1
2
3
4
while(//user wants to keep playing && money > 0)
{
    //code for the whole game
}
Last edited on
Topic archived. No new replies allowed.