posted design solution

advertisement
CS 201EA
Project 5, Design
John Mallozzi
Problem
Write a program that plays the game of craps.
The Game
The player throws two dice. Add the two numbers that appear. If the total on the two dice is 7 or 11,
the player wins. If the total on the two dice is 2, 3, or 12, the player loses. Otherwise, the total on
the two dice is called the point. The player then keep throwing the dice until either the point occurs
again, in which case the player wins, or 7 occurs, in which case the player loses.
Sample Runs
You threw 5. Your point is 5.
You threw 3. Throw again.
You threw 6. Throw again.
You threw 10. Throw again.
You threw 9. Throw again.
You threw 10. Throw again.
You threw 9. Throw again.
You threw 8. Throw again.
You threw 7. You lose.
On another occasion, the output might be simply
You threw 7. You win.
or
You threw 3. You lose.
Algorithm






Make a random-number generator
Randomly generate two integers between 1 and 6, inclusive.
Calculate the sum of the two integers.
If the sum of the two integers is 2, 3, or 12, give losing message (as in sample run, above) and
stop the game.
If the sum of the two integers is 7 or 11, give winning message (as in sample run, above) and
stop the game.
Otherwise, sum of the two integers is the point. Give continuation message (as above), and then
repeat the following as long as there is neither a win nor a loss
o Randomly generate two integers between 1 and 6, inclusive.
o Calculate the sum of the two integers.
o If the sum of the integers is equal to the point, give winning message (as in sample run,
above) and stop the game.
o
If the sum of the integers is equal to 7, give losing message (as in sample run, above)
and stop the game.
Download