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

Make a program that will simulate the game of craps. Roll a pair of dice first r

ID: 3805304 • Letter: M

Question

Make a program that will simulate the game of craps. Roll a pair of dice first roll If first roll is 7 or 11, Win If first roll is 2, 3, or 12, "lose" If first rol is something else, keep rolling until you get 7 or the same total as first roll: 7 lose Same as first roll win Examples: First roll 11 win First roll 3 lose First roll 6 First roll 8 10 11 12 6 win 7 loses Requirements Use a do-while loop Make a function called rollDice that simulates rolling a pair of dice. This function simulates rolling a pair of dice. It returns a random number between 2 and 12. rollDice To simulate a roll of dice, think of 2 separate dice. Die 1 Die 2 roll (rando Grand0 6+ 1); use this one 0%6+1) generates a random number between 1 and 6 The following simulates 1 big die that has ll sides from 2 to 12 roll (rand0 11 2); Don't use this generates a random number between 2 and 12

Explanation / Answer

#include <stdio.h>
#include <time.h>
#include<stdlib.h>
int rolDice(void);
int main(void)
{
int rol, i, count, pp=0, tp=0, wc=0, lc=0, ht=0, rc=0, wr[35]={0}, lr[35]={0}, tw=0, tl=0;
enum Gamestat {WIN,LOSE,CONTINUE};
enum Gamestat stat;
srand(time(0));
printf(" Type times that U want to play");
scanf("%d", &ht);
for(i=1; i<=ht; i++)
{
printf(" Start U'r Game");
rc++;
rol = rolDice();
printf(" Rolled Dice: %d",rol);
count=1;
switch(rol)
{
case 7:
case 11:
stat = WIN;
printf(" You Win Dice in %d",count);
wc++;
wr[count]++;
break;
case 2:
stat=LOSE;
printf(" You Lose Dice in %d",count);
lc++;
lr[count]++;
break;
default:
stat = CONTINUE;
tp = rol;
printf(" Target point is: %d",rol);
while(stat == CONTINUE)
{
count++;
printf(" Dice Rolled Again");
rc++;
printf(" Rolled: %d", rol=rolDice());
if(tp == rol)
{
printf(" WIN IN %d", count);
wc++;
wr[count++];
stat = WIN;
}
else if(7 == rol)
{
printf(" LOSE in %d",count);
lc++;
lr[count++];
stat = LOSE;
}
else
{
stat = CONTINUE;
}
}
}
}
for(i=0; i<35; i++)
{
tw += wr[i];
}
for(i=0; i<=35; i++)
{
tl += lr[i];
}
printf(" Total Winners: %d",wc);
printf(" Total Losers:%d",lc);
printf(" Dice Rolled: %d",rc);
for(i=0; i<35; i++)
{
printf(" %4d Game Win on Rolling: %2d",wr[i],i);
printf(" %4d Game Losing on Rolling: %2d",lr[i],i);
}
printf(" The Total Chance of Winning are: %2f",100.0 * tw/ht);
printf(" The Total Average Length of the Game is: %2f",(double)rc/ht);
return 0;
}
int rolDice(void)
{
return(rand()%6+1) + (rand()%6+1);
}

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