Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi I am in Fundamentals of Programming One. We are working in C++. If you could answer this programming problem using functions, DO NOT use

Hi I am in Fundamentals of Programming One. We are working in C++. If you could answer this programming problem using functions, DO NOT use arrays. Thank you!!

For all programs for the rest of the semester you must provide good internal documentation. The first lines of your source code should be comments that include your name and date as the first line, followed by a description of the problem the program solves. Throughout your program, use meaningful variable names. All function definitions must start with a comment block that describes the functions task and the Preconditions and Postconditions for the function. Any area of code that needs explanation needs to be preceded by a comment block. A popular game of chance is a dice game known as "craps". You are to write a program to simulate a craps game. The rules of craps are as follows: A player rolls two dice. If the sum is 7 or 11 on the first throw, the player wins. If the sum is 2, 3, or 12 on the first throw (called "craps"), the player loses. If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then that sum becomes the player's "point". If you dont win or lose on the first roll, you must continue rolling the dice until you win or lose. If you "make your point" you win; if you roll a 7 you lose. You will use C++ library functions to generate random numbers to simulate rolling dice. You will need to use two library functions contained in the header file and one library function contained in the header file. The srand function provides a seed value to initialize the random number generator. (Without a different seed value, your program would get the same results every time you ran it.) The srand function is a void function which requires an unsigned integer parameter. To provide a different seed each time you run the program, you can use a library function called time. The time function with a parameter of 0 returns the current "calendar time" in seconds. You then need to convert this value to an unsigned int and pass it to the srand function as follows: srand ( unsigned (time(0)) ); This call to srand needs to be done only once at the very beginning of your program, so put it as the first executable statement in main. The rand library function is a value-returning function which returns a random integer between 0 and RAND_MAX (a constant defined in .) An example of a function call to rand(): value = rand(); Since you want only a number between 1 and 6, what will you need to do? Design your program with the following functions called by a short and simple main. Write a value-returning function which performs everything necessary to simulate the rolling of two dice: Ask the user to hit Enter to roll the dice. Use cin.get(ch); where ch has been defined as a char variable. Get two random values for the dice by using two calls to the rand function. Call the function explained below to display the face for each die rolled Return the sum of the two dice to the calling function. Write a void function that prints a block of characters that look like the die face for the value sent to the function. (This function prints ONE die face.) Example block of characters:

________

| O O |

| O O |

| O O |

________

P.S. This is a very crappy example of a die but it give the idea

Write a void function to print the rules of craps. Call this once at the start of the program. Write a function to keep rolling until the point is made or the player loses. It will need the point as an input parameter. This function will also call the function which rolls the dice. This function will be called from main when it is determined that the player did not win or lose on the first roll. Your program should declare the current player a loser or a winner. Add the logic in main to ask if the user wants to play again or stop. You will have to use cin.ignore(40,' '); after you ask the user to play again. Turn in sample output for the following scenarios: Win on first roll, Lose on first roll, Win after making the point, Lose while trying to make the point.

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

Step: 3

blur-text-image

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

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions

Question

Discuss the general principles of management given by Henri Fayol

Answered: 1 week ago

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago