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

A player rolls two dice. Each die has sixfaces. These faces contain 1,2,3,4,5, a

ID: 3612791 • Letter: A

Question

A player rolls two dice. Each die has sixfaces. These faces contain 1,2,3,4,5, and 6 spots. Afterthe dice have come to rest, the sum of the spots on the two upwardfaces 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 onthe first throw, then that sum becomes the player’s“points.” To win, you must continue rolling thedice until you “make your points.” The playerloses by rolling a 7 before making the points.

Make a program to simulate the game of craps for 100 times andprint number of the wins in first roll, lost in first roll, winswith points, and lost with points.

Explanation / Answer

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

int main(void){

int dice1;

int dice2;

int total;

int winOrLose;

int key = 0;

srand(time(NULL));

dice1 = rand() % 6 + 1;

dice2 = rand() % 6 + 1;

total = dice1 + dice2;

if(total == 7 || total ==11){

winOrLose = 1;

}

else if(total == 2 ||total == 2 || total == 12){

winOrLose = 0;

}

printf("total:%d ",total);

while(winOrLose != 0 &&winOrLose != 1){

key = total;

dice1 = rand() % 6 + 1;

dice2 = rand() % 6 + 1;

total = dice1 + dice2;

if(total == 7)

winOrLose = 0;

else if(total ==key)

winOrLose = 1;

}

printf("total: %d winOrLose: %d key:%d ",total,winOrLose,key);

if(winOrLose == 1)

printf("PlayerWin ");

else

printf("PlayerLoses ");

system("PAUSE");

return 0;

}

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