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

Roll two dice. Each die has six facesrepresenting values 1, 2, ...., and 6, resp

ID: 3682423 • Letter: R

Question

Roll two dice. Each die has six facesrepresenting values 1, 2, ...., and 6, respectively. Check the sumof the two dice. If the sum is 2, 3, or 12 (called craps), youlose; if the sum is 7 or 11 (called natural), you win; if the sumis another value (i.e., 4, 5, 6, 8, 9, or 10), a point isestablished. Continue until you roll either a 7 (you lose) or thesame point value (you win). Include a void function, called GetRoll, that takes one integer parameter and generates a random roll of a die. Include a void function, called CalcSum, that takes three integer parameters and determines the sum of the two given rolls. Include a void function, called PrintRoll, that takes three integer parameters and outputs the message describing the two rolled values and their sum, as shown below: Sample runs of the program: 1. you rolled 5 + 6 = 11 you win. 2. you rolled 1 + 2 = 3 you lose 3. you rolled 4 + 4 = 8 point is 8 you rolled 6 + 2 = 8 you win 4 you rolled 3 + 2 = 5 point is 5 you rolled 2 + 5 = 7 you lose

Explanation / Answer

#include <iostream.h>

#include <stdio.h>

#include<stdlib.h>

#ifndef _cplusplus

typedef unsigned char bool;

static const bool false=0;

static const bool true =1;

#endif

void GetRoll(void);

void CalcSum(int, int, int &);

void PrintRoll(int, int, int);

int main(void)

{

int dice1, dice2, totalrolls;

PrintRoll(dice1, dice2, totalrolls);

return 0;

}

void GetRoll()

{

      int x = rand()%6 + 1;

      cout<<x;

}

void CalcSum(int dice1, int dice2, int & totalrolls)

{

int n;

srand((unsigned)time(NULL));

dice1= rand()%6+1;

dice2= rand()%6+1;

totalrolls = dice1 + dice2;

cout<<"You rolled"<<dice1<<" + "<<dice2<<" = "<<totalrolls;

}

void PrintRoll(int dice1, int dice2, int totalrolls)

{

bool shoutern;

int summa, game, points, win[100]={0},lose[100]={0},n=0,i=0;

summa = Calcsum(dice1,dice2,totalrolls);

switch(summa)

{

case 7:

case 11:

shoutern = true;

cout<<"You Win ";

win[n]++;

break;

case 2:

case 3:

case 12:

shoutern=false;

cout<<"You Lose ";

lose[i]++;

break;

case 4:

case 5:

case 6:

case 8:

case 9:

case 10:

points=summa;

cout<<"your point is: "<<points;

break;

}

}

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