Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Write a C++ program that plays the game of Yahtzee. Here are instructions for playing the game: Your game will allow 1-2 players, and at

Write a C++ program that plays the game of Yahtzee. Here are instructions for playing the game: Your game will allow 1-2 players, and at the end, you need to ask if the user wants to play again and with how many players. There are 5 six-sided dice in the game and you get three rolls to try to make something on the scoresheet. The top half of the scoresheet is only a sum of 1 or more of dice you are trying to get: 1s, 2s, 3s, 4s, 5s, and 6s, and if you score 63 or more points in this section, you get an additional 35 points. The bottom half of the scoresheet consist of options that have pre-defined points or a total of all the dice. You have the options for a three of a kind (total of all dice, but has to have 3 or more of the same number), four of a kind (total of all dice, but has to have 4 or more of the same number), full house (25 pts, 2 dice the same and 3 dice the same), small straight (30 pts, 4 numbers in a row), large straight (40 pts, 5 numbers in a row), Yahtzee (50 pts, 5 dice the same number), up to 3 bonus Yahtzees (100 pts each, 5 dice the same number), and chance (total of all dice, any combination). After your first roll, a player can choose to roll 0-5 specific dice again. If the player chooses not to roll again or has rolled 3 times, then the player must choose a category not previously chosen on the scoresheet. If the dice do not match the rules for that category, then the player takes a 0 for that category. Once a category has a score (even a zero score), it cannot be chosen again!!! The bonus Yahtzee can only be chosen if there is a non-zero score in the Yahtzee!!! The players turn is over once a category is chosen, and the game is over once all players have put a score in all categories. The final score is a total points from the two sections, including the bonus if the top section is 63 or greater. Command-line argument To support various numbers of players, you will run the program with the specific number at runtime, rather than prompting for the input. The user can enter the number of players, 1-2. Any other command line argument is an error. 1-player Example: ./yahtzee 1. It should be able to take any number of players Your program must be able to : Print an error message and recover, when the player doesnt supply a valid category. This includes selecting a category with a score. Print an error message when the user enters an invalid option as a command line argument. You do not need to recover from this. Correctly determine the score for the category based on the dice (Remember, if the dice do not match the rules for the category, then a zero score is place in that category). Play the game correctly based on rules and number of players. Continue to play until the user selects no. Your functions are 15 lines or less You must not have any global variables You must use a dynamic 1-d array for each players scoresheet. You must not have memory leaks.

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_2

Step: 3

blur-text-image_3

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

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students explore these related Databases questions

Question

Find the measure of (T. 10.62 m 6.61 m 6.14m

Answered: 3 weeks ago