EBK ABSOLUTE C++
EBK ABSOLUTE C++
6th Edition
ISBN: 9780133970944
Author: SAVITCH
Publisher: PEARSON CUSTOM PUB.(CONSIGNMENT)
bartleby

Videos

Textbook Question
Book Icon
Chapter 3, Problem 11PP

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 2-6 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 player’s total score and it becomes the other player’s 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 opponent’s 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: keep rolling on the computer’s turn until it has accumulated 20 or more points, then hold. Of course, if the computer wins or rolls a I then the turn ends immediately. Allow the human to roll first.

int humanTurn (int humanTota1Score) ;

int computerTurn ( int computerTota1Score) ;

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.

Blurred answer
Students have asked these similar questions
In the Dice Roll game, the player begins with a score of 1000. The player is prompted for the numberof points to risk and a second prompt asks the player to choose either high or low. The player rollstwo dice and the outcome is compared to the player’s choice of high or low. If the dice total is between2 and 6 inclusive, then it is considered “low”. A total between 8 and 12 inclusive is “high”. A total of7 is neither high nor low, and the player loses the points at risk. If the player had called correctly, thepoints at risk are doubled and added to the total points. For a wrong call, the player loses the points atrisk. Create a DiceRollGame application that uses a DRPlayer object based on this specification. TheDRPlayer object should have two Die member variables that represent the dice. The Die class shoulduse a random number generator to determine the outcome in a roll() method. Application outputshould look similar to:
he Dice game of “Pig” can be played with the following rules. Roll two six-sided dice. Add the face values together. Choose whether to roll the dice again or pass the dice to your opponent. If you pass, then you get to bank any points earned on your turn. Those points become permanent. If you roll again, then add your result to your previous score, but you run the risk of losing all points earned since your opponent had rolled.  Continue to roll as much as you want. However, once a “1” comes up on either die, your score is reduced to 0, leaving you only with points that you have previously "banked." Furthermore, you must pass the dice to your opponent. The first person to 100 points is the winner. When a player rolls two dice, the possible outcomes are as follows:   Die #2 Roll Roll a 1 Roll a 2 Roll a 3 Roll a 4 Roll a 5 Roll a 6 Die #1 Roll Roll a 1 0 0 0 0 0 0 Roll a 2 0 4 5 6 7 8 Roll a 3 0 5 6 7 8 9 Roll a 4 0 6 7 8 9 10 Roll a 5 0 7 8 9 10 11 Roll a 6 0 8 9 10…
The Penny Pitch game is popular in amusement parks. Pennies are tossed onto aboard that has certain areas marked with different prizes. For example: The prizes available on this board are puzzle, game, ball, poster, and doll. At the end ofthe game, if all of the squares that say BALL are covered by a penny, the player gets theball. This is also true for the other prizes. The board is made up of 25 squares (5 x 5).Each prize appears on three randomly chosen squares so that 15 squares contain prizes.Create a penny_pitch application that displays a Penny Pitch board (use [ and ] toindicate squares) with prizes randomly placed and then simulates ten pennies being randomly pitched onto the board. After the pennies have been pitched, the applicationshould display a message indicating which prizes have been won, it any.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole
Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges; Author: FreecodeCamp.org;https://www.youtube.com/watch?v=oBt53YbR9Kk;License: Standard YouTube License, CC-BY