In this homework assignment you will write a c program to


Assignment

This assignment will use: while loops, for loops, if else blocks, basic arrays, random numbers, and boolean values.

In this homework assignment you will write a c++ program to play a simple version of the dice game, Yahtzee. The object of Yahtzee (or our simple version), is to roll 5 dice with the purpose of getting all 5 dice to show the same number.

Store your 5 dice as an int array of size 5. Use rand()%6+1 to get a random dice value between 1 and 6. After your first roll of the dice, print the dice values to the screen, and ask the user which number they would like to hold. To get all dice the same number, the user will "hold" all the dice of one number, and roll the other dice to try and get them to be the same number.

For example, if the dice read 5 5 2 4 1, it is the best strategy to hold the two 5 dice, and re-roll the 2 4 and 1. Then, in the dice array, 2 4 1 will be regenerated with random values between 1 and 6. Eventually all dice will be a 5, and you have a Yahtzee! After the user gets a Yahtzee, display to the screen which number they got a Yahtzee with, and how many turns it took to get a Yahtzee.

After displaying the results of the Yahtzee game, ask the user if they would like to play again. If the user enters a ‘y', play the game again. If the user enters anything else, end the program.

Use a while loop to play the game over and over, if the user enters a ‘y' to play again. Use a while loop to roll the dice while you are trying to get a Yahtzee. Use for loops to generate the random dice values, and print the dice to the screen after each turn. Use booleans where appropriate (like to control the while loops), and ints and chars where appropriate

Sample Console Output:
Welcome to Yahtzee!!!
Here is your first roll:
5 5 2 4 1
Pick a number to hold (usually the number with the most dice): 5
Here is your roll:
5 5 1 5 1
Pick a number to hold (usually the number with the most dice): 5
Here is your roll:
5 5 5 5 5
You got a yahtzee!! with the number 5, in 3 turns
Would you like to play again?(y/n) y
Welcome to Yahtzee
Here is your roll:
4 3 6 6 2
Pick a number to hold (usually the number with the most dice): 6
Here is your roll:
5 1 6 6 5
Pick a number to hold (usually the number with the most dice): 6
Here is your roll:
4 4 6 6 6
Pick a number to hold (usually the number with the most dice): 6
Here is your roll:
6 6 6 6 6
You got a yahtzee!! with the number 6 in 4 turns
Would you like to play again?(y/n) n
Have a great day!

Code Style and Naming Conventions:

You need to follow the style and naming conventions used in class. Name variables with good descriptive names, and give proper spacing and indentation to your code to make it easy to follow. Add good comments to your code, that explain what your program does.

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: In this homework assignment you will write a c program to
Reference No:- TGS02315456

Expected delivery within 24 Hours