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 run in visual studio. A Game of Chance One

ID: 3714713 • Letter: I

Question

It is a C++ program. make sure it can run in visual studio.

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 surm 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 a7 before making the point

Explanation / Answer

Solution:

code:

#include<iostream> //i/o library

#include <stdlib.h>
#include <time.h>
using namespace std;
int play_craps();

int main(void)
{
int i;
int winScore = 0, loseScore = 0, firstRollwin = 0, firstRollLost = 0, res = 0;
for(i=0;i<100;i++) {
res = play_craps();
//cout<<"tes."<<res;
if(res == 0) {
// nothing do .. winning in other rounds
}
else if(res > 0){
winScore += res;
firstRollwin++;
}
else{
loseScore += (-1*res);
firstRollLost++;
}
}
// printing results
cout<<" Number of wins in first roll: "<<firstRollwin;
cout<<" Wins with points: "<<firstRollwin;
cout<<" Number of loses in first roll: "<<firstRollLost;
cout<<" Losss with points: " <<loseScore;
return 0;
}

int play_craps()
{
int getRandomInteger(int a, int b);
srand(time(NULL));

int dice1,dice2,dice3,dice4,roll,roll2;
// dice rolling and getting score
dice1=getRandomInteger(1,6);
dice2=getRandomInteger(1,6);
roll=dice1 + dice2;

if(roll==7 || roll==11)
{ //first roll win
printf("You Win in first round! ");
return roll;
}
else if(roll==2 || roll==3 || roll==12)
{ //first roll lose
printf("You Lose in first round ");
return -1*roll;
}
else
{ // second round roll
do
{
dice3=getRandomInteger(1,6);
dice4=getRandomInteger(1,6);
roll2=dice3 + dice4;
if(roll2==roll)
{
cout<<" You Win";
return 0;
}
}while(roll2 != 7);
cout<<" You Lose";
return 0;
}

}
// rolling dice...
int getRandomInteger(int aa, int bb)
{
return rand()%(bb-aa+1)+aa;
}

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote