CS 1400 Lab #18: Designing a Dice Game


Objectives:

The objective of this lab is to help you understand how to write code that validates input, and uses loops together with branches and random numbers.

Study Material

  1. Do it again?
  2. Using loops to validate input
  3. Random Numbers
  4. For Loops

The problem

For this assignment, you will be desiging a program that simulates rolling a pair of dice. You will not actually write the program at this point. Your program will perform the following steps:

  1. Create a Random Number generator object.
  2. Ask the user if they want to roll the dice
  3. Get the user's response and validate that it is either 'y' or 'n'. If it is not a 'y' or an 'n', tell the user that the input is invalid and ask for another response.
  4. If the user responds with a 'y' then
    1. Generate two random numbers in the range 1 - 6
    2. If the two numbers are 6 and 6, display the message "You rolled boxcars"
    3. If the two numbers are 1 and 1 display the message "You rolled snake-eyes"
    4. In all other cases display the message "You rolled ..." and show the values of the two random numbers
    5. Return to step 2 and ask the user again if they want to roll the dice.
  5. If the user responds with a 'n', print a goodbye message and quit.

Deriving the Solution

This program is an application of the things that you have studied in this lab. To begin, Fill out the Algorithm Design Worksheet. Draw an Activity Diagram that describes the steps outlined above and write the pseudo-code for this program as you have learned to do in previous labs.

Writing the Pseudo-Code

Start Visual Studio and create a new console project. Call it lab18. Copy the line-by line description of your program from the Algorithm Design Worksheet to your new project. Mark each line of pseudo-code as a comment. Your pseudo-code must be complete and describe the loops and decisons required to make your program work.

Questions

When you submit your lab, write down the answers to the following two questions as comments to your submission.

(1) Suppose that in your dice game you let the user roll the dice exactly ten times. What kind of loop would you use in this case?

(2) Suppose that in your dice game, you let the user keep rolling the dice until a seven was rolled. What kind of loop would you use in this case?

File(s) to Submit:

Place your complete project folder in zip file and name the zip file lab_18_your-initials_V1.0.zip. For example, I would name my file lab_18_RKD_V1.0.zip. Submit this assignment as Lab #18 on Canvas. Please do not include any other files in your submission.

Grading Guidelines

Description Points possible

Assignment meets grading guidelines:
o Source code files contain a declaration that you did not copy any code, except that provided.
o Assignment has been properly submitted to Canvas
o Code meets style guidelines
o Code contains a Console.ReadLine( ) statement at the end

2

Your pseudo-code describes the steps requited to write the dice playing program.

3

You have correctly answered the two questions in this lab.

2
Total 7