C++ programming language, starting out with C++.
Looping Constructs
Write a program to simulate the casino game "craps".
It should execute N number of games so that you can compute
the
probability(%) of the "player" winning and the "house" winning.
Probability(%) of the "player" winning = PlayerWins / N * 100.
Probability(%) of the "house" winning = HouseWins / N * 100.
The rules are:
Player rolls two dice.
When the sum is 7 or 11 on first throw, player wins. Game
over.
When the sum is 2, 3, or 12 on first throw, "house" wins. Game
over.
When the sum is 4,5,6,8,9, or 10 on first throw,
that sum becomes the player's "point".
Now, to win the player must continue rolling the dice until
he
matches "point"; however should he roll a 7 then the "house"
wins.
That concludes the game.
Run six(6) Simulations to complete the Table:
Number of Games %Prob(PlayerWins) %Prob(HouseWins)
---------------------------------------------------------
1,000
10,000
100,000
1,000,000
10,000,000
100,000,000
// C++ program to simulate the casino game "craps".
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
srand(time(NULL)); // set the seed for random
number generator
int totalGames = 6; // total number of
simulations
int gameNo = 0;
int numGames[] = {1000, 10000, 100000, 1000000,
10000000, 100000000}; // number of games in each simulation
int playerWins = 0, houseWins = 0;
int dice1, dice2, point;
cout<<left<<setw(20)<<"Number of
Games"<<left<<setw(20)<<"%Prob(PlayerWins)"<<left<<setw(20)<<"%Prob(HouseWins)"<<endl;
// loop that continues till all the simulations are
over
while(gameNo < totalGames)
{
// set the playerWins and houseWins
to 0 at the start of each simulation
playerWins = 0;
houseWins = 0;
// loop for number of games in that
simulation
for(int
i=1;i<=numGames[gameNo];i++)
{
// generate the
dice roll for 2 die
dice1 = rand()%6
+ 1;
dice2 = rand()%6
+ 1;
point = dice1 + dice2 ; // get the point
// sum of die
is 7 or 11 in first roll
if(point == 7 ||
point == 11)
{
playerWins++;
}else if(point
== 2 || point == 3 || point == 12) // sum of die is 2,3 or 12 in
first roll
{
houseWins++;
}else
{
// loop that continues till the user rolls the
point or 7 in subsequent roll
do
{
dice1 = rand()%6 + 1;
dice2 = rand()%6 + 1;
if((dice1 + dice2 ) ==
7)
{
houseWins++;
break;
}
}while((dice1 + dice2) != point);
if((dice1+ dice2) == point)
playerWins++;
}
}
// output the result of
simulation
cout<<left<<setw(20)<<(numGames[gameNo])<<left<<setw(20)<<(((double)(playerWins))/numGames[gameNo])*100<<left<<setw(20)<<(((double)(houseWins))/numGames[gameNo])*100<<endl;
gameNo++;
}
return 0;
}
//end of program
Output:

C++ programming language, starting out with C++. Looping Constructs Write a program to simulate the casino...
Write a Complete Java program for the following specification: 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. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If...
in c programming and c++filed
Exercise 1: A Game of guessing number Set the default upper and lower limits to be 1-100, and ask you to guess a number. If you do not guess the correct number, the program will nicely" automatically adjust the upper or the lower limits to save your day until you guess it. 2 0 12. 51 - 100 3 2 51 74 22 65 74 85 2 71 74 3 . 2 73 74 75...
9. In the casino dice game Craps, players make wagers on a sequence of rolls of a pair of dice. A sequence of rolls starts with the "shooter" making an initial roll of two dice called the "come-out” roll. If the sum of the dice on the initial roll is 7 or 11 then a player with a bet on the Pass Line wins. If the initial roll results in a sum of 2, 3, or 12 ("craps") then a...
Please write the program in python: 3. Design and implement a simulation of the game of volleyball. Normal volleyball is played like racquetball, in that a team can only score points when it is serving. Games are played to 15, but must be won by at least two points. 7. Craps is a dice game played at many casinos. A player rolls a pair of normal six-sided dice. If the initial roll is 2, 3, or 12, the player loses....
Problem 9 A single game of craps (a dice game) consists of at most two rolls of a pair of six sided dice. The ways to win are as follows: Win-the first roll of the pair of dice sums to either 7 or 1 (you win, game over, no second roll Win the first roll of the pair of dice does NOT sum to either 7 or 1 but the sum of the second roll is equal to the sum...
C# Code: Write the code that simulates the gambling game of craps. To play the game, a player rolls a pair of dice (2 die). After the dice come to rest, the sum of the faces of the 2 die is calculated. If the sum is 7 or 11 on the first throw, the player wins and the game is over. If the sum is 2, 3, or 12 on the first throw, the player loses and the game is...
Write a c++ program that simulates a million of games in craps. I am having a trouble getting to loop a million of times. I am trying to use a const for a million. This is the code so far. #include <iostream> #include <cstdlib>// contains prototypes for functions srand and rand #include <ctime>// contains prototype for function time #include <iomanip> using namespace std; int rollDice(); // rolls dice, calculates and displays sum void printstats(); int totroll = 0, games, point,...
(6(4 pts) A player (Joe) goes to a casino and plays a fair game. The player may wager any amount of money. There is a 0.5 probability of winning. If the player wins, then the player get twice the amount of the bet in winnings. If the player loses, the player gets nothing. Think of betting on a coin toss. If you win you double your money, if you lose you lose your money. This is a "fair" game because...
III. Overview & Requirements:
The following description has been adopted from Deitel &
Deitel. One of the most popular games of chance is a dice game
called "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. After the dice have come to
rest, the sum of the spots on...
Write a C++ game that plays Craps. Craps is a game played with a pair of dice. The shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the ‘come out roll’) is a 7 or 11, the shooter wins the game. If the opening roll results in a 2 (snake eyes), 3 or 12 (box cars), the shooter loses,...