Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Project 11* (Note the difference between the book assignment and the actual assignment below) from Chapter 3 of Absolute C++ 5 th ed. (Savitch),

Programming Project 11* (Note the difference between the book assignment and the actual assignment below) from Chapter 3 of Absolute C++ 5 th ed. (Savitch), pg. 141: 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: If the player rolls a 26 then he or she can either

ROLL AGAIN or

HOLD.

At this point the sum of all rolls made this turn is added to the players total score and it becomes the other players turn. If the player rolls a 1 then the player loses his or her turn. The player gets no new points and it becomes the opponents turn. If a player reaches 100 or more points after holding then the player wins. Write a program that plays the game of Pig, where one player is a human and the other is the computer. Allow the human to input r to roll again or h to hold.

The computer program should play according to the following rule:

Generate a random number before deciding whether to hold or roll again. If the generated number is odd, the computer rolls again. If it is even, the computer holds. Note that this generated number is NOT the same as the previous dice roll.

Of course, if the computer wins or rolls a 1 then the turn ends immediately. Allow the human to roll first.

Write your program using at least two functions:

int humanTurn( int humanTotalScore);

int computerTurn( int computerTotalScore);

These functions should perform the necessary logic to handle a single turn for either the computer or the human. The input parameter is the total score for the human or computer. The functions should return the turn total to be added to the total score upon completion of the turn. For example, if the human rolls a 3 and 6 and then holds, then humanTurn should return 9. However, if the human rolls a 3 and 6 and then a 1, then the function should return 0.

After every dice roll, the user should be prompted for what to do next. If its the computers turn, the user should be prompted to enter c to continue if the computer holds or if the computer rolls a 1 (basically, at the end of the computers turn). If its the humans turn, the user should be prompted for c to continue if their turn has ended due to rolling a 1, or for r or h to determine whether the human wants to roll again or hold. See the sample output on the following pages. Obviously your output will not be the same due to (pseudo)randomness, but I should be able to play the entire game and it should follow all the rules described above.

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

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions