CPS 6: Assignment 4

Summer 1999

Gamblin Fool

Due Wednesday, June. 9, 11:59pm

12 points

Change into your cps6 directory and create a directory called "assign4". Change into the "assign4" directory. If you did this correctly, when you type "pwd" you should see a long path name that ends with "/cps6/assign4"

In order to do this assignment, you need to copy a Makefile using the following "cp" command (don't forget the trailing period, or dot):

 cp  ~dr/cps6/assign4/*  .

This command will copy files in the directory ~dr/cps6/assign4 into your directory for you to use. If you type "ls" you should see "Makefile" and "slotgame.cc".

For the programming problem that follows, you should use the style rules discussed in class, which includes meaningful variable names, indentation, and comments at the top of the file and for each function.

Problem: Making Money

Refer to the Dice class in Chapter 5 of your textbook for this problem.

Write a program slotgame.cc to play the slot machine. The file slotgame.cc has been provided for you to help you get started. Your program should do the following.

  1. Ask the gambler how much money he/she wants to spend.
  2. Ask the gambler which dollar machine he/she wants to play (one, five or ten). The gambler will type in the word not the integer (ten, not the number 10). Money is exchanged for the corresponding coins: either 10 dollar coins, 5 dollar coins, or 1 dollar coins.
  3. Spend all the money possible in the slot machine. If the gambler wanted to spend 17 dollars and play the 5 dollar machine, then he/she would spend 15 dollars. Inform the gambler that the extra 2 dollars is not spent.
  4. The slot machine has three wheels that spin. The left and right wheels have the numbers 1-10 on them. The middle wheel has the numbers 1-9 and a special symbol "*" which matches with anything. For each coin entered in the machine, the handle is pulled and the wheels spin, eventually stopping.
  5. The gambler never spends his winnings.
  6. Each time the wheel is spun, show the three numbers (or "*") and print a message if the gambler won.
  7. At the end, print a message indicating how much money the gambler won, and a message indicating if the gambler made money, lost money, or broke even. Money not spent (for example, the 2 dollars in the example above) is not used in the comparison.

In addition, your program should have at least two meaningful functions besides the main function. These functions must be organized in such a way that you do not pass Dice as parameters. We'll learn later in the semester how to pass class objects as parameters

Below are two sample runs. Your output does not have to look exactly like this, but should follow the specifications above.

> slotgame
How many dollars do you want to spend:? 7
Which dollar machine do you wish to play (one, five, or ten)? one
Spinning... Numbers are: 2 9 1
Spinning... Numbers are: 5 * 9
*** Congrats, won $2
Spinning... Numbers are: 8 * 8
*** Congrats, won $10
Spinning... Numbers are: 9 2 2
*** Congrats, won $2
Spinning... Numbers are: 8 7 5
Spinning... Numbers are: 4 * 5
*** Congrats, won $2
Spinning... Numbers are: 9 9 2
*** Congrats, won $2
Total winnings are $18
You won money!
>> slotgame
How many dollars do you want to spend:? 88
Which dollar machine do you wish to play (one, five, or ten)? ten
You can spend all but 8 dollars
Spinning... Numbers are: 7 2 4
Spinning... Numbers are: 8 7 10
Spinning... Numbers are: 5 7 4
Spinning... Numbers are: 7 4 6
Spinning... Numbers are: 10 * 3
*** Congrats, won $20
Spinning... Numbers are: 2 9 3
Spinning... Numbers are: 4 5 7
Spinning... Numbers are: 3 * 5
*** Congrats, won $20
Total winnings are $40
You lost money!
>

Extra Credit (2 pts): Error Checking and more Repetition(optional)

Make a copy of the program slotgame.cc called slotgameX.cc using the "cp" command by typing:

 cp slotgame.cc slotgameX.cc
Modify slotgameX.cc in the following manner.

  1. If there is a typo when the gambler types in the word one, five or ten, then tell the gambler their option is not available and ask them to try again. Repeat this until the gambler finally types in one of the three valid options.

  2. After a complete game (all the money allocated has been played in the slot machine), if the gambler won money, ask if he/she would like to play their winnings (yes or no). If the gambler responds yes, then play another game with the winnings. Repeat this step at the end of each game.

Here is a sample run:

>> slotgame
How many dollars do you want to spend:? 88
Which dollar machine do you wish to play (one, five, or ten)? tne
We do not have a tne slot machine. (one, five, or ten)? fve
We do not have a fve slot machine. (one, five, or ten)? ten
You can spend all but 8 dollars
Spinning... Numbers are: 6 3 1
Spinning... Numbers are: 5 7 10
Spinning... Numbers are: 4 6 1
Spinning... Numbers are: 7 4 3
Spinning... Numbers are: 10 * 8
*** Congrats, won $20
Spinning... Numbers are: 1 9 3
Spinning... Numbers are: 2 8 6
Spinning... Numbers are: 1 * 5
*** Congrats, won $20
Total winnings are $40
You lost money!
Do you want to play your winnings? (yes or no): yes
Spinning... Numbers are: 9 8 9
*** Congrats, won $20
Spinning... Numbers are: 5 6 7
Spinning... Numbers are: 1 6 3
Spinning... Numbers are: 2 4 7
You lost money!
Do you want to play your winnings? (yes or no): yes
Spinning... Numbers are: 8 3 1
Spinning... Numbers are: 2 7 5
You lost money!
You have no more money, go home.
>

Submitting Programs

When your programs compile and produce the correct output, create a "README" file (please use all capital letters). Include your name, section number, the date, and an estimate of how long you worked on the assignment in the "README" file. You must also include a list of names of all those people with whom you collaborated on the assignment.

To submit your programs electronically type (leave off slotgameX.cc if you did not do the extra credit):

    submit6 assign4 README slotgame.cc slotgameX.cc

You should receive a message telling you that the program was submitted correctly.