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

Write a C program that plays the game of craps. A player rolls two dice, each di

ID: 3721737 • Letter: W

Question

Write a C program that plays the game of craps. A player rolls two dice, each dice has numbers 1-6. If the sum = 7 or 11, player wins. If sum = 2, 3, 12, player loses. If the sum is anything else, the game continues, the sum becomes the player’s “points”. The game keeps playing until the player rolls the sum of “points” again, in this case player wins. I player rolls a 7 after the “point” then player loses. Write a C program that plays the game of craps. A player rolls two dice, each dice has numbers 1-6. If the sum = 7 or 11, player wins. If sum = 2, 3, 12, player loses. If the sum is anything else, the game continues, the sum becomes the player’s “points”. The game keeps playing until the player rolls the sum of “points” again, in this case player wins. I player rolls a 7 after the “point” then player loses.

Explanation / Answer

PLEASE REFER BELOW CODE

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

int main()
{
int dice1,dice2,sum,total_score;
srand(time(0)); //see points for random number generation

total_score = 0;
while(1)
{
printf("Rolling dice ....... ");
dice1 = (rand() %(6 - 1 + 1)) + 1; //generating two random numbers and use as score
dice2 = (rand() %(6 - 1 + 1)) + 1;
printf("Dice 1 scored = %d ", dice1);
printf("Dice 2 scored = %d ", dice2);
sum = (dice1 + dice2); //sum of both score
total_score += sum; //adding sum to total score
if((sum == 7) || (sum == 11)) //if sum is 7 or 11 then player wins
{
printf("Hola ! You won (@@) ");
printf("You have earned %d points ", total_score);
break;
}
else if((sum == 2) || (sum == 3) || (sum == 12)) //if score is 2,3 and 12 then player loose
{
printf("Sorry!! You loose (- -) ");
printf("You have earned %d points ", total_score);
break;
}
else //game continues
{
printf(" Game continues ...... ");
}

}
return 0;
}

PLEASE REFER BELOW OUTPUT

Rolling dice .......

Dice 1 scored = 3
Dice 2 scored = 2


Game continues ......

Rolling dice .......

Dice 1 scored = 4
Dice 2 scored = 4


Game continues ......

Rolling dice .......

Dice 1 scored = 3
Dice 2 scored = 5


Game continues ......

Rolling dice .......

Dice 1 scored = 1
Dice 2 scored = 1
Sorry!! You loose (- -)
You have earned 23 points

Process returned 0 (0x0) execution time : 0.037 s
Press any key to continue.

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