Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ASCI C PROGRAMMING Seeking help with homework Write a program that plays a dice game with the user. First, study the program diceGameEZ.c (below) which

ASCI C PROGRAMMING Seeking help with homework

Write a program that plays a dice game with the user. First, study the program diceGameEZ.c (below) which plays a simple dice game. Next, implement the dice game described below by thoughtfully modifying the first program. (Or starting from scratch if you want.) /* Dice Game The game consists of 7 rounds. Each round consists of the player's turn followed by the computer's turn. Each round is either won by the player, or won by the computer. The winner of the game is whoever wins the most rounds. The player's turn: The player throws three dice. The player's score for the turn is the largest value of the three dice. The player may choose to reject the throw and throw three dice again (but in this case the computer will throw four dice.) The new score is again the largest value of the three dice. Only the first throw may be rejected. The outcome of the second throw (if done) is the player's score for the turn. The computer's turn: The computer throws three or four dice. The computer throws four dice when the player threw twice. The computer's score for the turn is the largest value of the dice thrown. The winner of the round is whoever has the highest score. In the case of a tie, the computer wins the round.

-----------------------------------------------------------------

#include  #include  #include  /* Easy dice game | | The game consists of 7 rounds. | In each round, the computer throws a die, | then the human throws a die. | The winner of the round is the player who has the highest throw. | In case of a tie, neither player wins. | The winner of the game is the player who has won the most rounds. | If both have won the same, the game is a tie. | */ char input[132]; /* user input buffer */ /* Throw a single 6-sided die | */ int throwDie() { static int initialized = 0; int num; if ( !initialized ) { printf("Initializing Die "); srand( time(NULL) ); initialized = 1; } num = rand()%6 + 1 ; return num; } /* Human turn | | Modify this for the assignment | */ int humanTurn() { int toss; toss = throwDie(); printf("Human throws a %d ", toss ); return toss; } /* Computer turn | | Modify this for the assignment | */ int computerTurn() { int toss; toss = throwDie(); printf("Computer throws a %d ", toss ); return toss; } int main(int argc, char *argv[]) { int round, humanWins=0, computerWins=0 ; int humanToss, computerToss; const int numberOfRounds = 7; /* Play the Rounds */ for ( round = 1; round<=numberOfRounds; round++ ) { printf(" Round %d ", round ); printf("Player's Turn: (hit enter)"); gets( input ); /* pause for dramatic effect */ humanToss = humanTurn(); printf("Computer's Turn: (hit enter)"); gets( input ); /* pause for dramatic effect */ computerToss = computerTurn(); /* Determine Winner of the Round */ if ( humanToss > computerToss ) { humanWins++; printf("\tHuman wins the round. human: %3d. computer: %3d ", humanWins, computerWins ); } else if ( computerToss > humanToss ) { computerWins++; printf("\tComputer wins the round. human:%3d. computer: %3d ", humanWins, computerWins ); } else if ( computerToss == humanToss) { printf("\tTie. human:%3d. computer: %3d ", humanWins, computerWins ); } } /* Determine Winner of the Game */ if ( humanWins > computerWins ) printf(" WINNER!! The human wins the game! "); else if ( computerWins > humanWins ) printf(" The computer wins the game! "); else printf(" Tie Game! "); printf(" "); return 0; }

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

Recommended Textbook for

Essential Data Protection For Estate Agencies In Singapore 2024

Authors: Yang Yen Thaw Yt

1st Edition

B0CQK79WD3, 979-8872095392

More Books

Students also viewed these Databases questions

Question

When a browser sends a request ro a server, the server

Answered: 1 week ago