CS 1400 Lab #19: Making a Dice Game


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. You designed a solution to this problem in the last lab.

The problem

For this assignment, you will be writing a program that simulates rolling a pair of dice. 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

You should have developed the design for this program in lab #18.

Writing the Code

Start Visual Studio and start the project you created for lab #18. Now, fill in the C# code that will implement The pseudo-code that you wrote in lab #18. Notice how your pseudo-code now serves as documentation for your code. It makes it easier for others to understand how your program works.


When you submit this lab, add some comments to your submission to answer the following questions:

(1) Given a Random Number generator object named "joe", write the statement you would use to generate a random number between 5 and 10, inclusive.

(2) What is the best kind of loop to use when writing a loop that gets input from the user and tests it to make sure the input is a valid response. If the response is not valid, code in the loop will display an error message and ask the user to enter his or her input again.

File(s) to Submit:

Place your complete project folder in a zip file and name the zip file lab_19_your-initials_V1.0.zip. For example, I would name my file lab_19_RKD_V1.0.zip. Submit this assignment as Lab #19 on Canvas.

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


Your program works and meets all requirements.


You have correctly answered the questions in this lab.

Total 7