Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

* It is a C++ program. Make sure it can work in visual studio 2015. A Game of Ch

ID: 3720012 • Letter: #

Question

* It is a C++ program. Make sure it can work in visual studio 2015.

A Game of Chance One of the most popular games of chance is a dice game known as "craps," which is played in casinos and back alleys throughout the world. The rules of the game are straightforward: A player rolls two dice. Each die has six faces. These faces contain 1,2,3,4,5, and 6 spots, respectively. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on the first throw, the player wins. If the sum is 2, 3 or 12 on the first throw (called "craps"), the player loses (i.e., the "house" wins). If the sum is 4, 5, 6, 8,9 or 10 on the first throw, that sum becomes the player's "point." To win, you must continue rolling the dice until you "make your point" (i.e., roll your point value). The player loses by rolling a 7 before making the point.

Explanation / Answer

//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64

#include <iostream>

int main()
{
  
//Declare variables
  
int dice1, dice2 = 0;
int rollDice;
char repeat = 'y';


//Check if user wants to play again?
while (repeat == 'y' || repeat == 'Y')
  
{
//Welcome message
std::cout<<"###Welcome to Casino###"<<" ";
  
//Calculate both dices using rand() function
dice1 = rand() % 6 + 1;
dice2 = rand() % 6 + 1;
  
// Take sum of both dices
rollDice = dice1 + dice2;

//Display what user rolled
  
std::cout << "Your rolled " << rollDice<<" ";
  
//Check if user won
if (rollDice == 7 || rollDice == 11)
{
std::cout << " Congrats.. You Won !" << " " ;
}

//Check if user lost
else if (rollDice == 2 || rollDice == 3 || rollDice == 12)
{
std::cout << "Craps... House Wins!" << " ";
}
  
//Check for third condition

else if (rollDice == 4 || rollDice == 5 ||rollDice == 6 ||rollDice == 8 || rollDice == 9 || rollDice == 10)
{
dice1 = rand() % 6 + 1;
dice2 = rand() % 6 + 1;
int second = dice1 + dice2;

std::cout<<"Rolling again !"<<" ";
std::cout << " Now You rolled " << second <<" ";
  
if( second == rollDice )
{
std::cout<< " Congrats.. You Won !" << " " ;
break;
}
else if( second == 7 )
{
std::cout << "Craps... House Wins!" << " ";
break;
}
}
  
//Check if user wants to paly again?
  
std::cout <<"Another game? Enter Y to repeat" << " ";
std::cin >> repeat;
}
  
return 0;
}