Question

In: Computer Science

PROGRAMMING IN C-DICE GAME Q1. A player rolls two dice at the same time. Each die...

PROGRAMMING IN C-DICE GAME

Q1.

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 2 or 10 on the first throw, the player wins.

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

(iii) If the sum is 4, 5, 6, 8, 9 or 11 on the first throw, the sum becomes the player’s point. To win, the player must continue rolling the dice until he/she makes the point again. However, the player loses by rolling a 10 before making the point.

Solutions

Expert Solution

Thanks for the question. Here is the complete program in C.

=======================================================================

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

int main(){

               

                srand(time(NULL));

                int dice_one=0, dice_two=0;

                char c;

               

               

                printf("Welcome!\n");

               

                while(1){

                               

                                printf("Hit any key to roll the dice.");

                                scanf("%c",&c);

                                dice_one=rand()%6 +1;

                                dice_two=rand()%6 +1;

                                printf("You rolled %d %d in your first throw. Total = %d\n",dice_one,dice_two,dice_one+dice_two);

                                if(dice_one+dice_two==2 || dice_one+dice_two==10){

                                                printf("You Win!\n");

                                                break;

                                }

                                else if(dice_one+dice_two==3 || dice_one+dice_two==7 ||dice_one+dice_two==12){

                                                printf("You Lose!\n");

                                                break;

                                }

                                int points = dice_one+dice_two;

                                printf("\nYour point now is %d. You must get %d to win now.\n\n",points,points);

                                do{

                                                printf("\nHit any key to roll the dice.\n");

                                                scanf("%c",&c);

                                                dice_one=rand()%6 +1;

                                                dice_two=rand()%6 +1;

                                                printf("You rolled %d %d.Total = %d\n",dice_one,dice_two,dice_one+dice_two);

                                                if(dice_one+dice_two==points){

                                                                printf("You Win!\n\n",points);

                                                }

                                                else if(dice_one+dice_two==points){

                                                                printf("Your rolled 10. You Lose!\n");

                                                }

                                               

                                }while(dice_one+dice_two!=points && dice_one+dice_two!=10);

                               

                                break;

}   

}

=======================================================================


Related Solutions

In a dice game a player first rolls two dice. If the two numbers are l...
In a dice game a player first rolls two dice. If the two numbers are l ≤ m then he wins if the third roll n has l≤n≤m. In words if he rolls a 5 and a 2, then he wins if the third roll is 2,3,4, or 5, while if he rolls two 4’s his only chance of winning is to roll another 4. What is the probability he wins?
In the game of Lucky Sevens, the player rolls a pair of dice. If the dots...
In the game of Lucky Sevens, the player rolls a pair of dice. If the dots add up to 7, the player wins $4; otherwise, the player loses $1. Suppose that, to entice the gullible, a casino tells players that there are lots of ways to win: (1, 6), (2, 5), and so on. A little mathematical analysis reveals that there are not enough ways to win to make the game worthwhile; however, because many people’s eyes glaze over at...
In the game of Lucky Sevens, the player rolls a pair of dice. If the dots...
In the game of Lucky Sevens, the player rolls a pair of dice. If the dots add up to 7, the player wins $4; otherwise, the player loses $1. Suppose that, to entice the gullible, a casino tells players that there are many ways to win: (1, 6), (2, 5), and soon. A little mathematical analysis reveals that there are not enough ways to win to make the game worthwhile; however, because many people's eyes glaze over at the first...
In the game of craps, a player (known as the shooter) rolls two fair six-sided dice....
In the game of craps, a player (known as the shooter) rolls two fair six-sided dice. The shooter immediately loses if the sum of the dice is 2, 3, or 12 and immediately wins if the sum of the dice is 7 or 11 on the first roll. If the sum is anything else (4, 5, 6, 8, 9, or 10), that number becomes the point and the shooter rolls again. The shooter now wins by rolling that same point...
You make a carnival game, where the player rolls two fair dice (in a single roll)...
You make a carnival game, where the player rolls two fair dice (in a single roll) and attempts to roll doubles (meaning both dice show the same number). The player puts down a dollar to play the game. If the player loses, they lose their dollar. If the player wins, they win $3 (and do not lose their original dollar). Answer the following (5 pts total). If you are running the game, what is the expected value of how much...
A game works as follows: each player rolls one dice (let's call it ''n''). After both...
A game works as follows: each player rolls one dice (let's call it ''n''). After both players have made the first roll, they have the choice to leave or not. If a player exits, he automatically looses; if not, he rolls a second time (let's call this second roll "m'') and receives nm points . The player with the most points wins, in case of a tie no one wins. a) Give the fundamental space of the two throws. b)...
The game of Pig is a simple two-player dice game in which the first player to...
The game of Pig is a simple two-player dice game in which the first player to reach 100 or more points wins. How to play: Players take turns rolling one six-sided dice and following these rules: If the player rolls 2 through 6, then he/she can either a. “Roll Again” or b. “Hold” At this point, the sum of all rolls is added to the player’s score, and it becomes the other player’s turn. If the player rolls 1 before...
A game works as follows: the player rolls one dice once (let's call it ''n'') and...
A game works as follows: the player rolls one dice once (let's call it ''n'') and then he rolls it second time (let's call this second roll "m'') and receives nm points . A)What is the probability that n = 1 knowing that the player has received more than 20 points. b) What is the probability that m = 1 knowing that the player has received more than 20 points. c) (What is the probability that the player receives more...
At a charity event, a player rolls a pair of dice. If the player roles a...
At a charity event, a player rolls a pair of dice. If the player roles a pair (same number on each die), the player wins $10. If the two are exactly one number a part (like a five and a six), the player wins $6. IF the player roles a one and a six, they win $15. Otherwise, they lose. If it cost $5 to play, find the expected value. Write a complete sentence to explain what your answer means...
PYTHON GAME OF PIG The game of Pig is a simple two player dice game in...
PYTHON GAME OF PIG The game of Pig is a simple two player dice game in which the first player to reach 100 or more points wins. Players take turns. On each turn a player rolls a six-sided die. After each roll: a) If the player rolls a 1 then the player gets no new points and it becomes the other player’s turn. b) If the player rolls 2-6 then they can either roll again or hold. If the player...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT