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.
You will create a function called rollDice that will, when called, roll two dice and return a random number between 2 and 12. Each time rollDice is called, the program should output the result of the roll
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.
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
int dice1, dice2 = 0;
int rollDice;
char repeat = 'y';
cout << "**********************************************************"<< endl;
cout << "******** Welcome to the Kyung Bae Choi Casino ********"<< endl;
cout << "********* Step up to the table and place your bets! ******"<< endl;
cout << "**********************************************************"<< endl;
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 if (rollDice == 4 || rollDice == 5 ||rollDice == 6 ||rollDice == 8 || rollDice == 9 || rollDice == 10)
{
dice1 = rand() % 6 + 1;
dice2 = rand() % 6 + 1;
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;
}
}
This does output only 7. so, it keep saying Your rolled 7. Winner ! Another game? Y(es) or N(o). And, if i put y, the program ends. or if i put n, the program output the "thank you for playing!" endlessly.
what is problem??
How can I make it continually re-rolling the dice until the player rolls the winning "point" or rolls a seven.