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

Draw a flow chart that model the following game of rolling two dice: A player ro

ID: 3773655 • Letter: D

Question

Draw a flow chart that model the following game of rolling two dice: A player rolls two dice at the same time.

Each die has six faces, which 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.

(i) If the sum is 7 or 11 on the first throw, the player wins.

(ii) If the sum is 2, 3, or 12 on the first throw, the player loses.

(iii) If the sum is 4, 5, 6, 8, 9 or 10 on the first throw, the sum becomes the player’s point. To win, you must continue rolling the dice until you make your point. However, the player loses by rolling a 7 before making the point. Sample runs for the game are as follows:

Player rolled 5 + 6 = 11

Player wins

Player rolled 4 + 1 = 5

Point is 5

Player rolled 6 + 2 = 8

Player rolled 1 + 2 = 3

Player rolled 3 + 2 = 5

Player wins

Player rolled 4 + 6 = 10

Point is 10

Player rolled 3 + 4 = 7

Player loses

Player rolled 1 + 1 = 2

Player loses.

Then, write a complete C program to solve the problem (hint: The dice rolling are random, therefore the numbers face upward are random. Use rand( ) function to simulate the random numbers from rolling dice).

Explanation / Answer

<code>

#include<stdio.h>
int main()
{
int a,b;
int flag = 0;
srand( time(NULL));
a = (rand()%6) + 1;
b = (rand()%6) + 1;

while(1) {
printf("Player rolled %d + %d = %d ", a,b,(a+b));

if((a+b) == 7 || (a+b) == 11) {
printf("%s ","Player Wins");
break;
}else if((a+b) == 2 || (a+b) == 3 || (a+b) == 12){
printf("%s ","Player Loses");
break;
}else {
int point = (a+b);
printf("Point is %d",point);
a = (rand()%6) + 1;
b = (rand()%6) + 1;
while(1) {
printf("Player rolled %d + %d = %d ", a,b,(a+b));

if((a+b) == point) {
printf("%s ","Player Wins");
break;
}else if((a+b) == 7) {
printf("%s ","Player Loses");
break;
}else {
a = (rand()%6) + 1;
b = (rand()%6) + 1;
}
}
break;
}
}
return 0;
}

</code>

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