Need help with Dice rolling Code! Please!

Im supposed to create a betting program to where the user rolls two dice and if the user rolls a 7 with dice 1 and dice 2 added up, the user wins. Anything else, the user loses. The user starts with $500 and should be able to lose money and win money allowing the user to make money or lose money.

Im having problems with allowing the user to continue to play after his first bet. And Im having issues with establishing the new user "money balance" when he starts a new bet. Here's what I have.... Thanks in Advance!!

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
#include <iostream>
#include <ctime>
using namespace std;
int main()
{

	int balance;
	int bet_money;
	int start = 500;
	bool loop1 = true;
	bool loop2 = true;
	int diceone;
	int dicetwo;

	cout << "***** Welcome to SEVENS! The betting dice game! *****" << endl << endl;
	cout << "Wager whatever you'd like. If you roll a 7, you win whatever you bet!" << endl << endl;
	cout << "But beware, if you don't roll a 7, you lose your wager" << endl << endl;
	cout << "Enter a negative bet if you'd like to quit the game early" << endl << endl;
	cout << "LETS BEGIN!!!" << endl << endl;
	cout << " " << endl << endl;
	cout << "You have $" << start << " remaining" << endl << endl;

	while (loop1) {

		cout << "Place your bet: ";
		cin >> bet_money;
		if (bet_money <= 500 && bet_money >= 0) {
			loop1 = false;
		}
		else {
			loop1 = true;
			cout << "Insufficent value enetered..." << endl;
		}
	}
		
	start += (bet_money);
	loop2 = true;
	while (loop2) {
		// Enter for first dice roll.
		cin.get();
		cin.get();
		srand(time(0));
		diceone = rand() % 6 + 1;
		dicetwo = rand() % 6 + 1;
		cout << "You rolled " << diceone << " and " << dicetwo << " = " << dicetwo + diceone << endl;


		if ((dicetwo + diceone) == 7) {
			cout << "You win!!" << endl;
			
		}
		else if ((dicetwo + diceone) != 7) {
			cout << "You Lose!!" << endl;

		}
		else {
			cout << " " << endl;
		}

		cin.ignore();
	}
}
Lines 27 and 28 set loop1 to false if you enter a value between 0 500, you need to set loop1 to true somewhere in the loop2 body or a conditional if statement.

As for the betmoney,

1
2
3
4
5
6
7
8
9
		if ((dicetwo + diceone) == 7) {
			cout << "You win!!" << endl;
			startmoney+=betmoney;
		}
		else if ((dicetwo + diceone) != 7) {
			cout << "You Lose!!" << endl;
                        startmoney-=betmoney;

		}

and not have it run once in the main function.
Last edited on
I understood what you did with the bet_money, but Im just confused as to where, why and how to "set loop1 to true somewhere in the loop2 body". Sorry if Im a little slow, New to C++.
Thanks again!
You never set loop1 true to true, so it will never run loop1 again after the first time. I recommend making them into methods/functions instead of having it in main.
Do I understand correctly: You want the user to play many times?
So you need to put everything in a big loop?
Topic archived. No new replies allowed.