You are on page 1of 2

CMPT 300: Laboratory 4

Dice, Conditionals & Loops 8%


Due: Tuesday March 1st @ 2355hrs

The primary objective of this laboratory is to understand conditional execution and repetition.

Laboratory Procedure:
Create the following directory tree:

~/CMPT300/Lab4/

Inside of the Lab4 directory develop the following:

Develop code to simulate a simple dice game. The dice game has the following
rules:
1. The player starts with $100
2. The player will roll one 6-sided die.
3. The player will roll a number of dice equal to the value of the roll in
step 2.
4. Sum the value of each die from step 3.
5. If the sum from step 3 is even, then the player will lose an amount equal
to the sum, otherwise the player will gain an amount equal to the sum.
6. Repeat steps 2–6 until the player loses all of their money, or until they
double their initial money.

Your program will simulate the dice game, and provide an indication of each of
the values throughout execution in the following form:
Roll # 1
------------------------------------
Player’s Money: $100
Die roll: 6
Dice rolls: 6 5 4 3 2 1
Sum: 21
Result: Gained $21

Roll # 2
------------------------------------
Player’s Money: $121
Die roll: 1
Dice rolls: 2
Sum: 2
Result: Lost $2

Your Program will run until one of two termination conditions are met, at which
point the program will indicate the outcome:

Roll # 22
------------------------------------
Player’s Money: $198
Die roll: 3
Dice rolls: 4 2 5
Sum: 11
Result: Gained $11

+++++ You Won! Congratulations +++++


or:
Roll # 10232143
------------------------------------
Player’s Money: $8
Die roll: 5
Dice rolls: 2 2 2 2 2
Sum: 10
Result: Lost $10

------- I’m Sorry, You Lost! -------

Program Requirements:
§ Your program will not require any user input at runtime and all results will be written to
the terminal.
§ Develop your code so that the number of sides on the die, the initial amount
of money, and the amount required to win is variable.
§ You are expected to use at least 2 different looping structures within your
code! i.e. (while, for, or do..while loops)
§ The program output is expected to exactly match the specification! Marks will be
deducted for any/all deviations!
§ Programs must be well documented (commented), and you must select appropriate data
types for each of the inputs (i.e. int, float, double, string, etc.)
§ Constants should be declared as such (i.e. const PI = 3.14159265).

Grading
Program Output ................................................. 1
Looping Structures ............................................. 3
Variable Minimization & Representation .......... 3
Documentation ................................................... 1

Total ..................................................................... 8

*** NOTE: Your code must compile and execute within the laboratory environment.
Failure to do so will result in a mark of ZERO for the program. ***

Submission
You must submit your entire Lab4 directory structure as a tar.gz archive.

To accomplish this navigate the terminal to the parent directory of your Lab4 directory:

$> cd ~/CMPT300

Create a tar.gz archive:

$> tar cvzf LASTNAME.tar.gz Lab4

Where LASTNAME is your last name! Finally, submit your archive LASTNAME.tar.gz online
through Moodle.

You might also like