0% found this document useful (0 votes)
63 views2 pages

Laboratory 4

This document provides instructions for Laboratory 4 in CMPT 300. The lab requires students to create a dice game simulation that uses conditionals and loops. The simulation tracks a player's money as they repeatedly roll dice, following rules where even sums lose money and odd sums gain money. Students must develop the code to be variable and include at least two different loop structures. They must also document and comment their code properly. The program output will be evaluated for 1 point, loop structures for 3 points, variable usage for 3 points, and documentation for 1 point, out of a total of 8 points. Students must submit their completed Lab4 directory as a tar.gz file through Moodle.

Uploaded by

waynexjoseph
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views2 pages

Laboratory 4

This document provides instructions for Laboratory 4 in CMPT 300. The lab requires students to create a dice game simulation that uses conditionals and loops. The simulation tracks a player's money as they repeatedly roll dice, following rules where even sums lose money and odd sums gain money. Students must develop the code to be variable and include at least two different loop structures. They must also document and comment their code properly. The program output will be evaluated for 1 point, loop structures for 3 points, variable usage for 3 points, and documentation for 1 point, out of a total of 8 points. Students must submit their completed Lab4 directory as a tar.gz file through Moodle.

Uploaded by

waynexjoseph
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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