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;
}
Last edited on
You have a syntax error on your line:
else (rollDice == 4 || rollDice == 5 ||rollDice == 6 ||rollDice == 8 || rollDice == 9 || rollDice == 10)
You either need to use (1) an else statement with not conditions or (2) an else if statement with conditions. Figure out which one you actually need to use.

Then within that block of code, you never update the values dice1 or dice2 which means sum2 will always equal roll dice, so the player will always win the game. You need to continually reroll the dice until the player rolls the winning "point" or rolls a seven.
Topic archived. No new replies allowed.