Question

In: Computer Science

C program with functions Make a dice game with the following characteristics: must be two players...

C program with functions

Make a dice game with the following characteristics:

must be two players with two dice.

when player 1 rolls the marker is annotated

when player 2 rolls the marker is annotated

in other words, for each roll the added scores must be shown.

Example:

Round 1:

player 1 score = 6

player 2 score = 8

Round 2:

player 1 score = 14

player 2 score = 20

Whoever reaches 35 points first wins.

if a player goes over 35 points, the last shot does not count, example:

If a player is at 30 points and when he rolls the two dice he gets 6 points, the sum (30 + 6) would be 36, it goes over 35 so that throw does not count and the score remains at 30.

Whoever gets double 3 or double 5 loses automatically.

Solutions

Expert Solution

here is the required solution

here is the code

#include <stdio.h>
#include<stdlib.h>
//function to get roll the dice
int rolldice()
{ //roll of dice1 and dice2
int dice1=rand()%6+1;
int dice2=rand()%6+1;
if(dice1==dice2 && (dice1==3 || dice1==5))
return -1;
else
return dice1+dice2;
}
int main()
{ //declaration of relevant variable
int player1=0,player2=0,prev1=-1,prev2,tem, i=1;
while(1)
{ printf("Round %d\n",i++);
tem=rolldice();
//check if double 3 or 5 occur
if(tem==-1)
{   
printf("Player 2 win");
break;
}
prev1=tem;
  
//add score if after adding score is less than 36
if(player1+prev1<=35)
player1=player1+prev1;
//if player1 reaches 35 than won
if(player1==35)
{
printf("player 1 win");
break;
}
printf("player 1 score=%d\n",player1);
tem=rolldice();
//check if double 3 or 5 occur
if(tem=-1)
{
printf("Player 1 win");
break;
}
prev2=tem;
//add score if after adding score is less than 36
if(player2+prev2<=35)
player2=player2+prev2;
printf("player 2 score=%d\n",player2);
//if player1 reaches 35 than won
if(player2==35)
{printf("Player 2 win");
break;}
  
//print the score
printf("player 1 score =%d\n",player1);
printf("player 2 score =%d\n",player2);
}
return 0;
}


Related Solutions

Craps is a dice game in which the players make wagers on the outcome of the...
Craps is a dice game in which the players make wagers on the outcome of the roll, or a series of rolls, of a pair of dice. Most outcomes depend on the sum of the up faces of two, fair, six-sided dice. 1) What is the lower class boundary of the "6" class? 2) Find the mean. 3) Find the standard deviation. 4) Find the z-score for snake eyes.
Two players A and B play a game of dice . They roll a pair of...
Two players A and B play a game of dice . They roll a pair of dice alternately . The player who rolls 7 first wins . If A starts then find the probability of B winning the game ?
Two players A and B play a dice game with a 6-face fair dice. Player A...
Two players A and B play a dice game with a 6-face fair dice. Player A is only allowed to roll the dice once. Player B is allowed to roll the dice maximally twice (that is, Player B can decide whether or not she or he would roll the dice again after seeing the value of the first roll). If the player with the larger final value of the dice wins, what is the maximal probability for Player B to...
I am using C++ Write a program that allows two players to play a game of...
I am using C++ Write a program that allows two players to play a game of tic-tac-toe. Use a two-dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: Displays the contents of the board array. Allows player 1 to select a location on the board for an X. The program should ask the user...
Dice Game Rules: 2 - 4 players Each player has 5 Dice. The dice have 6...
Dice Game Rules: 2 - 4 players Each player has 5 Dice. The dice have 6 sides. Each player rolls their dice, and the dice statistics are reported: Sum, number of pairs (and of what), and "straights" - (all dice in order - e.g. 1,2,3,4,5 or 2,3,4,5,6) Player 1 might roll 2,2,3,4,4 so the results would be: Sum: 15, 1 pair (2), 1 pair (4) Player 2 might roll 1, 1, 4, 6, 6 so the results would be: Sum:...
1. Consider the following game. There are two piles of matches and two players. The game...
1. Consider the following game. There are two piles of matches and two players. The game starts with Player 1 and thereafter the players take turns. When it is a player's turn, she can remove any number of matches from either pile. Each player is required to remove some number of matches if either pile has matches remaining, and can only remove matches from one pile at a time. Whichever player removes the last match wins the game. Winning gives...
In order to win a game, a player must throw two fair dice and the sum...
In order to win a game, a player must throw two fair dice and the sum of the dice needs to be either 4 or less or 10 or more for the player to win. What is the probability that the sum of the dice is 4 or less? What is the probability that the sum of the dice is 10 or more? What is the probability that the player will win the game?
Fill in the blanks. Players,(....) , and payoffs are the defining characteristics of a game. At...
Fill in the blanks. Players,(....) , and payoffs are the defining characteristics of a game. At the Nash equilibrium of a game, everyone is playing a (....) . A firms long-run supply curve is the portion of the [... ] cost that is above the marginal cost curve. The long-run competitive market equilibrium price must be such that all firms earn zero profit because [ ... ] . If [.......] is greater than marginal cost the firm can increase profits...
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)...
Design and implement a Python program which will allow two players to play the game of...
Design and implement a Python program which will allow two players to play the game of Tic-Tac-Toe in a 4x4 grid! X | O | X | O -------------- O | O | X | O -------------- X | X | O | X -------------- X | X | O | X The rules for this game is the same as the classic, 3x3, game – Each cell can hold one of the following three strings: "X", "O", or "...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT