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

One of the most popular games of chance is a dice game known as “craps,” which i

ID: 3762437 • Letter: O

Question

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 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, then that sum becomes the player’s “points.” To win, you must continue rolling the dice until you “make your points.” The player loses by rolling a 7 before making the points.

Write a program in C to simulate the game of craps for 100 times and print the number of wins in the first roll, lost in the first roll, wins with points, and lost with points.

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

void play_craps()

{

srand(time(NULL));

  

int die_1,die_2,die_3,die_4,roll,roll_2;

  

die_1=rand()%6 + 1;

die_2=rand()%6 + 1;

roll=die_1 + die_2;

printf("You rolled a %i ",roll);

  

if(roll==7 || roll==11)

{

printf("Congrats!! You Win! ");

return;

}

else if(roll==2 || roll==3 || roll==12)

{

printf("The house wins ");

return;

}

else

{

do

{

  

die_3=rand()%6 + 1;

die_4=rand()%6 + 1;

roll_2=die_3 + die_4;

printf("You rolled a %i ",roll_2);

if(roll_2==roll)

{

printf("You Win");

return;

}

}while(roll_2 != 7);

  

printf("You Lose");

}

  

}

int main()

{

char answer,junk;

do

{

printf(" Play game of craps(y/n):");

answer=getchar();

junk=getchar();

if(answer=='y' || answer=='Y')

play_craps();

}while(answer=='y' || answer=='Y');

  

printf(" ");

return 0;

}