C++ programming Craps game simulation

Write a C++ program that simulates the casino game of craps. These are the rules of the game:
• If a player throws a 7 or 11 (sum of two dice) on the first roll, the player wins the game.
• If a player throws a 2, 3 or 12 (sum of two dice) on the first roll, the player loses the game.
• If a player throws a 4, 5, 6, 8, 9 or 10 (sum of two dice) on the first roll, s(he) neither wins nor loses but creates a “point.” If this is the case, the player keeps rolling the dice until the point (4, 5, 6, 8, 9 or 10) is thrown again, and the player wins the game. However, if the player throws a 7 (sum of two dice) before the “point” is thrown, the player loses the game.

The program will ask the player ” Another game? Y(es) or N(o)?” and terminate whenever any key other than Y or y is pressed.

I don't understand what is wrong with it....


#include <iostream>
#include <ctime>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main()
{
cout << "**********************************************************"<< endl;
cout << "******** Welcome to the {000}Casino ********"<< endl;
cout << "********* Step up to the table and place your bets! ******"<< endl;
cout << "**********************************************************"<< endl;

int dice1, dice2 = 0;
int rollDice;
char repeat = 'y';

while (repeat == 'y' || repeat == 'Y')
{
dice1 = rand() % 6 + 1;
dice2 = rand() % 6 + 1;
rollDice = dice1 + dice2;

cout << "Your rolled " << rollDice;
if (rollDice == 7 || rollDice == 11)
{
cout << ". Winner !" << endl ;
}

else if (rollDice == 2 || rollDice == 3 || rollDice == 12)
{
cout << ". You lose!" << endl;
}

else (rollDice == 4 || rollDice == 5 ||rollDice == 6 ||rollDice == 8 || rollDice == 9 || rollDice == 10)
{ int sum2 = dice1 + dice2;
if( sum2 == rollDice )
{
cout << ". Winner !" << endl;
break;
}
else if( sum2 == 7 )
{
cout << ". You Lose!" << endl;
break;
}
}
cout <<"Another game? Y(es) or N(o)" << endl;
cin >> repeat;

while (repeat == 'n' || repeat == 'N')
{
cout << Thank you for playing!<< endl;
}
return 0;
}
You should format code with the code format tags. As you haven't node that, we have no idea what the code looks like to you.

Now that I've formatted your code, it should be obvious what's wrong with it.
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
#include <iostream>
#include <ctime>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main()
{
	cout << "**********************************************************"<< endl;
	cout << "******** Welcome to the {000}Casino ********"<< endl;
	cout << "********* Step up to the table and place your bets! ******"<< endl;
	cout << "**********************************************************"<< endl;

	int dice1, dice2 = 0;
	int rollDice;
	char repeat = 'y';

	while (repeat == 'y' || repeat == 'Y')
	{
		dice1 = rand() % 6 + 1;
		dice2 = rand() % 6 + 1;
		rollDice = dice1 + dice2;

		cout << "Your rolled " << rollDice;
		if (rollDice == 7 || rollDice == 11)
		{
			cout << ". Winner !" << endl ;
		}

		else if (rollDice == 2 || rollDice == 3 || rollDice == 12)
		{
			cout << ". You lose!" << endl;
		}

		else (rollDice == 4 || rollDice == 5 ||rollDice == 6 ||rollDice == 8 || rollDice == 9 || rollDice == 10) // kbw: synatx error here, missing "if"
		{ int sum2 = dice1 + dice2;
			if( sum2 == rollDice )
			{
				cout << ". Winner !" << endl;
				break;
			}
			else if( sum2 == 7 )
			{
				cout << ". You Lose!" << endl;
				break;
			}
		}
		cout <<"Another game? Y(es) or N(o)" << endl;
		cin >> repeat;
		// kbw: missing "}"

		while (repeat == 'n' || repeat == 'N') // kbw: pointless loop
		{
			cout << Thank you for playing!<< endl;
		}
		return 0;
	}
Last edited on
Topic archived. No new replies allowed.