Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Programming *************************************************************************** This is what I have so far. I need help making 2 dice. I can use the roll() twice, but the dice

C Programming

image text in transcribed

image text in transcribed

***************************************************************************

This is what I have so far. I need help making 2 dice. I can use the roll() twice, but the dice share the same value. I would like to make them have two different values.

#include // input/output library #include // NULL constant, srand() & rand() functions #include // access your computers clock time

#define PLAYER1SCORE 0 #define PLAYER2SCORE 0 #define TRUE 1 #define FALSE 0

int main() { int die1 = roll(); printf("Your roll is %d. ", die1); }

int roll(void) { srand( (unsigned)time(NULL) ); int dice = (rand( ) % 6) + 1; return dice; }

int calcPoints(int player, int* playerScore) { int dice = roll(); int turnScore = 0; int turnDone; if(dice == 1 || dice == 1) { turnScore = 0; turnDone = FALSE; } else if(dice == 1 && dice == 1) { turnScore = 25; } else if(dice == dice) { return (dice + dice) * 2; } else { playerScore = dice + turnScore; } }

Using C, write a simulated dice game of PIG. PIG requires two six-sided dice. The goal of the game is to be the first player to reach 100 points. On a turn, a player rolls the die repeatedly until either: A 1 is rolled Ifa 1 is rolled on a single die, that player's turn ends and no points are earned for the turn However, if "snake eyes" (or double 1's) are rolled, it earns 25 points All other doubles earn twice the value on the dice o o The player chooses to hold (stop rolling) o If the player chooses to hold, all the points rolled during that turn are added to his/her score Scoring Examples: Sherri rolls a 3 and a 4 then decides to continue. She then chooses to continue rolling 6 & 6,6& 4, 5 & 6,1 & 2. Because she rolled a 1, Sherri's turn ends and she earns O points. Craig rolls a 6&2 and decides to continue. He then chooses to continue rolling 3 & 4,5 &5 and then decides to hold. Craig earns 35 points for this turn: 6+2+3+4+2*(5+5)-35 Sample Output: Playerl score: 0 Player2 score: 0 Playerl rolls 4 and 2. Your total for this turn is6 Do you want to roll again (/N)? y Do you want to roll again (/N)? y Do you want to roll again (/N)? Playerl rolls 2 and 5. Your total for this turn is 13 Playerl rolls 1 and 1. Your total for this turn is 38 Player2 rolls 3 and 4. Your total for this turn is Do you want to roll again (/N)? y Do you want to roll again (/N)? y Do you want to roll again (/N)? y Player2 rolls 4 and 3. Your total for this turn is 14 Player2 rolls 3 and 4. Your total for this turn is 21 Player2 rolls 3 and 1. Your total for this turn is Playerl score: 38 Player2 score: 0 Playerl rolls 1 and 1. Your total for this turn is 25 Do you want to roll again (/N)? y Playerl rolls 2 and 6. Your total for this turn is 33 Do you want to roll again (/N)? Player2 rolls 6 and 5. Your total for this turn is 11 Do you want to roll again (/N)? y Do you want to roll again (/N)? y Do you want to roll again (/N)? Player2 rolls 3 and 5. Your total for this turn is 19 Player2 rolls 5 and 6. Your total for this turn is 30 @ieslinesiaRliiies oa litaillegiil UlliiiilEoesina: #include #include /NULL constant, srand & rand) functions // access your computer' s clock time // seed the random number generator using the computers clock srand (unsigned) time (NULL) // generate a random number between 0& 10 int num rand ( ) % 11; Program design Use top-down design to break the game into at least 3 different functions/ tasks. rollDice calcPoints Using C, write a simulated dice game of PIG. PIG requires two six-sided dice. The goal of the game is to be the first player to reach 100 points. On a turn, a player rolls the die repeatedly until either: A 1 is rolled Ifa 1 is rolled on a single die, that player's turn ends and no points are earned for the turn However, if "snake eyes" (or double 1's) are rolled, it earns 25 points All other doubles earn twice the value on the dice o o The player chooses to hold (stop rolling) o If the player chooses to hold, all the points rolled during that turn are added to his/her score Scoring Examples: Sherri rolls a 3 and a 4 then decides to continue. She then chooses to continue rolling 6 & 6,6& 4, 5 & 6,1 & 2. Because she rolled a 1, Sherri's turn ends and she earns O points. Craig rolls a 6&2 and decides to continue. He then chooses to continue rolling 3 & 4,5 &5 and then decides to hold. Craig earns 35 points for this turn: 6+2+3+4+2*(5+5)-35 Sample Output: Playerl score: 0 Player2 score: 0 Playerl rolls 4 and 2. Your total for this turn is6 Do you want to roll again (/N)? y Do you want to roll again (/N)? y Do you want to roll again (/N)? Playerl rolls 2 and 5. Your total for this turn is 13 Playerl rolls 1 and 1. Your total for this turn is 38 Player2 rolls 3 and 4. Your total for this turn is Do you want to roll again (/N)? y Do you want to roll again (/N)? y Do you want to roll again (/N)? y Player2 rolls 4 and 3. Your total for this turn is 14 Player2 rolls 3 and 4. Your total for this turn is 21 Player2 rolls 3 and 1. Your total for this turn is Playerl score: 38 Player2 score: 0 Playerl rolls 1 and 1. Your total for this turn is 25 Do you want to roll again (/N)? y Playerl rolls 2 and 6. Your total for this turn is 33 Do you want to roll again (/N)? Player2 rolls 6 and 5. Your total for this turn is 11 Do you want to roll again (/N)? y Do you want to roll again (/N)? y Do you want to roll again (/N)? Player2 rolls 3 and 5. Your total for this turn is 19 Player2 rolls 5 and 6. Your total for this turn is 30 @ieslinesiaRliiies oa litaillegiil UlliiiilEoesina: #include #include /NULL constant, srand & rand) functions // access your computer' s clock time // seed the random number generator using the computers clock srand (unsigned) time (NULL) // generate a random number between 0& 10 int num rand ( ) % 11; Program design Use top-down design to break the game into at least 3 different functions/ tasks. rollDice calcPoints

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is linear transformation? Define with example

Answered: 1 week ago