Question
Very short description: Write a program that allows the user to play the dice game Fifty. More detailed description: Your computer program should allow 2
Very short description:
Write a program that allows the user to play the dice game Fifty.
More detailed description:
Your computer program should allow 2 players to play the dice game Fifty. The rules for Fifty are as follows:
Goal: The goal of Fifty is to be the first player to reach 50 points. You get points by rolling doubles.
Play: The players decide who will be player 1 and who will be player 2. Player 1 goes first. A turn consists of a player rolling a pair of dice (with the goal of rolling doubles), and scoring the roll as described below. Play continues with each player taking one roll per turn. The first player to score 50 or more points is declared the winner.
Scoring: All doubles except 3s and 6s score 5 points. Double 6s are worth 25 points. Double 3s wipe out the players entire score, and the player must start again at 0. Non-double rolls are 0 points.
The program should allow the users to continue to play the game until they choose to quit.
Note: As you are developing and testing your program, you might want to make the winning score something smaller than 50, such as 10. It can take a while to reach 50 points. Just be sure to change it back to 50 before turning in the program.
To simulate the roll of the dice, the program must generate a random number from 1 to 6 for each die. Each of the random numbers is the value for each die. To generate a random number, C provides the rand() function. However, this function is a pseudo-random number generator. The very first time the rand() function is called, it will come up with the same number (not exactly what you want). Therefore, to give the rand function a different starting point each time, we can initialize the random generator with the time() function, which returns the number of seconds from the system clock. In other words, do the following at the beginning of your program:
srand((unsigned)time(NULL)); // seed random function with current time
// only needs to be done once
You need to include stdlib.h (i.e., #include
CS 102-03 Due: 10/16/2017
Fall 2018 Instructor: Vaidyanath Areyur Shanthakumar
The rand() function returns a number from 0 to RAND_MAX (which is usually at least 32,767). However, we need a number from 1 to 6. You can use the % (mod) operator to convert the number to the desired range. The following statement generates a random integer from 1 to 6:
int dice1 = (rand() % 6) + 1;
Program Requirements:
Your program must do the following
Print an introductory message at the beginning of the program to tell the user what the program does. This will give the user an idea of how to play the game. Allow the user to play games of Fifty with another player. Ask the user if they want to continue or quit the game. If one player chooses to quit the game, the other player wins. Users can choose if they want to play the game or quit. If they choose to play, then roll the dice. After each roll, show the player the result of the roll (the values of the dice). Output the scores for each player after each turn. Once a player reaches 50, the program should print a congratulatory message that includes which player won and the final score. Be sure any messages asking the user for a value clearly state how the user should enter the value. Example: Please press enter to continue playing or q to quit Your output should be clearly labeled and neatly formatted. Use good variable names and appropriate comments throughout your program. Make use of whitespace (blank lines, indenting, etc.) in order to make your program readable.
You must have a comment block at the beginning of your program that lists your name, the date, the class number and section and a description of what your program does. Be sure to test your program with various values to make sure it works properly. VERY IMPORTANT: Once the game is ended, print 10 lines of 20 * characters like this: ******************** ******************** ******************** ******************** ******************** ******************** ******************** ******************** ******************** ********************
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started