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

make a dice game program with this rule: A player rolls two dice. Each die has s

ID: 3629772 • Letter: M

Question

make a dice game program with this rule:

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.


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

Explanation / Answer

#include<stdio.h>


#include<time.h>
int main()
{

srand(time(NULL));
int winf=0, lostf=0, winp=0,lostp=0;
int die1,die2,sum;
int points=0,score=0;
int k=1;
for(k=1;k<=100;k++)
{
die1 = rand()%6 + 1;
die2 = rand()%6 + 1;
sum = die1+die2;
if((sum==7) || (sum==11)) {
winf++;
continue;
}
else if((sum==2) || (sum==3) || (sum==12)) {
lostf++;
continue;
}
else {
points=sum;
sum=0;
while(1) {
die1 = rand()%6 + 1;
die2 = rand()%6 + 1;
sum = die1 + die2;
score+=sum;
if(sum==7) {
lostp++;
break;
}
else if(score>=points)
{
winp++;
break;
}
}
}
}
printf(" number of wins in first roll: %d",winf);
printf(" number of lost in first roll: %d",lostf);
printf(" number of wins with points:: %d",winp);
printf(" number of wins with points:: %d",lostp);
return 0;
}