Ask C/C++ Expert


Home >> C/C++

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.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M92328627

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As