Craps game of hell

I bet you guys have already seen this assignment around here:
So here is the program statement
(1) One of the players goes first. That player announces the size of the bet, and rolls the dice. If the
player rolls a
• 7 or 11, it is called a natural. The player who rolled the dice wins.
• 2, 3 or 12, it is called craps. The player who rolled the dice loses.
• If the player's first roll is any other number (4, 5, 6, 8, 9, or 10) the bet is not immediately
decided. Instead, the number that the player rolled becomes the point and he continues to roll
the dice until either he rolls the point a 2nd time, in which case he wins, or he rolls a 7, in which
case he loses. For example, suppose a player's 1st roll is a 6.Then 6 becomes the point. He must
roll again. If his next roll were a 3, he would have to roll a 3rd time. The point remains 6. He
continues to roll the dice until he either gets a 6 (a win) or a 7 (a loss).
(2) When a player wins, he collects the bet, and gets to keep the dice and take another turn. Then the
play begins again with rule (1).
(3) When a player loses, his opponent collects the money that was bet and it becomes the opponent's
turn to roll the dice. The opponent starts play again with rule (1)
And when player 2 places a wager if his balance is greater than what it originally was he will wager 150 and if it is less he will wager 50. while player 1 always wagers 100.

I'm barely getting started with it. Unfortunately my dice won't roll random (they always equal 12), also, even when it rolls 12, the switch statement won't work. These are my 2 most pressing questions at the moment but as I move on I'm sure I'll have more!

Thanks for the help in advanced!

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
  #include <iostream>
#include <cstdlib>
#include <ctime> //for time!

using namespace std;

void sim();

int main() //main function
{
	int WagerNumber=1;
	int player1bet=100;
	int player2bet;
	int player2balance=1000;
	int die1 =(rand() % 6) + 1;
	int die2 =(rand() % 6) + 1;
	int totalroll = die1 + die2;
	int totalpoint = totalroll;

	srand(time(NULL)); //makes time random

	cout << "Wager " << WagerNumber << " : " << "Bet is " << player1bet << "." << endl;
	cout << "Player 1 is rolling the dice." << endl;
	cout << "The roll is a " << totalroll << "." << endl; 

	
	//switch case block gives you many options
	
	switch (totalroll)
	{
		case '7' : cout << "Natural! The player who rolled the dice wins!" << endl;
			break;
		case '11': cout << "Natural! The player who rolled the dice wins!" << endl;
			break;
		case '2' : cout << "Craps! The player who rolled the dice loses!" << endl;
			break;
		case '3' : cout << "Craps! The player who rolled the dice loses!" << endl;
			break;
		case '12': cout << "Craps! The player who rolled the dice loses!" << endl;
	}


	if (totalroll = 4||5||6||8||9||10)
		cout << "The point is " <<  totalpoint << " ." << "Player 1 rolls again."<< endl;


	//this if/else determines player2's bet according to his/her balance
	if (player2balance>=1000)
		player2bet=150;
	else if (player2balance<1000)
		player2bet=50;

return 0;
}
You need to seed the pseudo-random generator BEFORE you initialize any variables with pseudo-random numbers.
Move line 20 between lines 10 and 11.

Also, your switch statement doesn't work because you've declared totalroll as an integer on line 17, and in your switch statement you're treating it as a character.
You're also not breaking out of your case for 12.

*EDIT* also, '11' and '12' are not characters, not that it matters. ;)
Last edited on
Hey thanks that worked!!

But even when the dice roll a 7, it will skip the switch statement and go to the if, even if the 7 isn't included in the if.

How do I fix that?
Take them out of quotes.

'7' - char 7
7 - numeral 7
How do I treat totalroll as an integer in the switch statement? Or should I treat it as a char on line 17?

I also added the break out of case for 12 and removed the quotes.

Last edited on
@Last post: As Mats said, just remove the quotes.

Line 43: This line does not do anything close to what you want it to. :P Are those all the numbers not covered in the switch statement? You could just add a default to the switch statement...

1
2
3
4
5
6
7
8
9
10
11
12
13
switch (someint) {
case 0:
case 1:
case 2: //Fall-throughs!
    std::cout << "White sheep.\n";
    break;
case 3:
    std::cout << "Black sheep.\n";
    break;
default: //Executes if none of the other cases were triggered.
    std::cout << "You jolt awake after one of the sheep broke the laws of reality.\n";
    return 1;
}


-Albatross

Last edited on
Topic archived. No new replies allowed.