CMSC 201
Programming Project Three
B & F Lottery Pick-3
Out: Monday 10/25/99
Due: Before Midnight, Sunday 11/7/99
|
The Objective
The objective of this assignment is to incorporate all the aspects
of C programming we have discussed thus far this semester. This project
will give you experience with arrays, arrays used with functions,
random number generation and separate compilation.
The Background
B&F Lottery Inc., is a ficticious private lottery company that gives
one the opportunity to play three different lottery games.
These lottery games are "Pick-3", "Pick-4" and "Lotto6".
"Pick-3" is a game in which the player chooses a 3-digit number between
0-0-0 and 9-9-9. The player may choose to wager on all 3 digits, or
on certain subsets of the three digits. The Pick-3 wager types are:
All 3 digits
|
First 2 digits
|
Last 2 digits
|
First and Third digits
|
First digit only
|
Second digit only
|
Last digit only
|
The Task
Your task is to write a program that simulates the purchase of a
Pick-3 ticket, simulates the drawing of the winning Pick-3 number
and calculates the winnings. The following project parameters must
be followed--
Ticket Information
- Each ticket purchased is for only 1 drawing.
- The user chooses one 3-digit number per ticket
- There MUST be 3 wagers on a ticket
- Wager types (see above) are entered as integers -- a different integer for
each wager type
- Duplicate wager types on the same ticket are permitted
- Each wager type on the ticket may have a different wager amount
- As in project 1, wager amounts are between $.50 and $5.00 in
$.50 increments
Winning amounts
The Pick-3 game features "fixed" payouts. The amount won by the user
for each $.50 wager amount is predetermined according to the following
table
Wager Type | Payout per $.50
|
All 3 digits | $500
First 2 digits | $50
Last 2 digits | $50
First and Third digits | $50
First digit Only | $5
Second digit Only | $5
Third digit Only | $5
| | | | | | |
For example, if the user chooses the number 1-2-3 and the winning
number is 1-2-4, and wagers $1.00 on each wager type, then
A wager on All 3 Digits wins nothing
A wager on First 2 Digits wins $100
A wager on Last 2 Digits wins nothing
A wager on First and Third Digits wins nothing
A wager on First Digit Only wins $10
A wager on Second Digit Only wins $10
A wager on Third Digit Only wins nothing
Calculations
Your program must perform and display the following calculations
- Cost of each ticket purchased
- Amount won for each ticket
- Net amount (winnings - cost) for each ticket
- Total cost of all tickets purchased to be displayed when the user exits
- Total winnings of all tickets to be displayed when the user exits
- Net amount for all tickets purchased to be displayed when the user exists
Other Program requirements
In addition to the items list above, your program must meet the
following requirements:
- Display a greeting to the user
- When appropriate, display a list of wager types
- Validate all user input. Reprompt in a user-friendly way when invalid
values are input.
- Generate and display the winning numbers after each ticket purchase
- Your program must be broken up into multiple source files. The file
proj3.c may only contain main.
All other functions are contained in
the source file named pick3.c
- You must provide function prototypes and relevant #defines in the
file pick3.h
- Input the random number generator seed value from the user.
DO NOT use the current time to seed the random number generator!!!
Hints
- Design before you write code......a good design will lead you to
several simple functions that make the coding easier
- Use incremental development technique.
Sample Output
[102] a.out
Welcome to the B & F Lottery Pick-3 game
You will be purchasing pick-3 tickets with 3 wagers each
I will choose the winning number and calculate your winnings
Good Luck!!
Wager Type Enter Payout per $0.50
---------- ----- ----------------
All 3 Digits 1 $500
First 2 Digits 2 $50
Second 2 Digits 3 $50
First & Third Digits 4 $50
First Digit Only 5 $5
Second Digit Only 6 $5
Third Digit Only 7 $5
Please enter a seed for the random number generator: 23
Enter 1 to wager, 0 to quit: 1
Please enter a Pick-3 digit 1: 3
Please enter a Pick-3 digit 2: 9
Please enter a Pick-3 digit 3: 0
Please enter a Pick-3 wager type: 1
Input Pick-3 wager amount (cents): 50
Please enter a Pick-3 wager type: 4
Input Pick-3 wager amount (cents): 350
Please enter a Pick-3 wager type: 7
Input Pick-3 wager amount (cents): 50
Drawing pick-3 numbers....
Pick-3 winning numbers: 3-9-0
Ticket Info
Cost: $4.50
Winnings: $855.00
Net: $850.50
Enter 1 to wager, 0 to quit: 1
Please enter a Pick-3 digit 1: 6
Please enter a Pick-3 digit 2: 4
Please enter a Pick-3 digit 3: 3
Please enter a Pick-3 wager type: 0
Wager Type Enter Payout per $0.50
---------- ----- ----------------
All 3 Digits 1 $500
First 2 Digits 2 $50
Second 2 Digits 3 $50
Third 2 Digits 4 $50
First Digit Only 5 $5
Second Digit Only 6 $5
Third Digit Only 7 $5
Please enter a Pick-3 wager type: 5
Input Pick-3 wager amount (cents): 400
Please enter a Pick-3 wager type: 3
Input Pick-3 wager amount (cents): 200
Please enter a Pick-3 wager type: 1
Input Pick-3 wager amount (cents): 50
Drawing pick-3 numbers....
Pick-3 winning numbers: 6-2-9
Ticket Info
Cost: $6.50
Winnings: $40.00
Net: $33.50
Enter 1 to wager, 0 to quit: 0
Grand Totals
Nr Tickets: 2
Total Cost: $11.00
Total Won : $895.00
Total Net : $884.00
[103]
Although your output need not be identical to the above,
all information (including the greeting) must be present.
Submitting the Program
You must submit all files for your project. Late penalties will be determined
by the time and date of the last file submitted.
To submit your project, type the following at the Unix prompt.
Note that the project name starts with uppercase 'P'.
submit cs201 Proj3 proj3.c pick3.c pick3.h
To verify that your project was submitted, you can execute the
following command at the Unix prompt. It will show all files that
you submitted in a format similar to the Unix 'ls' command.
submitls cs201 Proj3