Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using C ++ Write a program to simulate the roll of a six-faced die. Youll need to write two programmer defined functions for this and

Using C ++

Write a program to simulate the roll of a six-faced die. Youll need to write two programmer defined functions for this and call one function from the other. The first function (lets call it Function A) calculates the value of the roll (1 through 6) and returns the value. Youll need to implement randomization in this function. The second function (lets call it Function B) implements the following logic

i) If the sum of two die rolls is greater than 9, the player wins

ii) If the sum of two die rolls is less than 5, the player loses.

iii) If the sum of two die rolls is 5, 6, 7, 8 or 9, the player gets to roll again It then returns whether the player has won or lost. You Function B must have a Boolean return type. From your main function, you need to print whether the player has won or lost.

HINT: Your main function can only call Function B, not both of them. Before implementing the above logic in Function B, call Function A from Function B to roll the die. Inside Function A, roll the die and return the roll value to Function B. Since you need two rolls, you will have to call Function A two times from Function B and get the two rolls. After getting the value for the two rolls, sum them and implement the above logic. Then, return a Boolean value signifying whether the player won or lost. Youll need a loop in Function B to roll again, if the player did not win or lose. For proper randomization, use srand(time(NULL)); in the main function, before you call Function B.

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

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago