CMSC 201
Programming Project Two
201's Modified KENO
Additional sections have been added to this project
description. The new sections have red headings. These modifications
were made Sat., 10/10/98.
Out: Wednesday 10/7/98
Due: Midnight Wednesday 10/21/98
|
The Objective
The objective of this assignment is for you to become familiar with
functions, random numbers, arrays and separate compilation.
The Background
The State of Maryland has a gambling game called KENO. In this project,
you will simulate playing KENO, but with easier rules.
For each game of KENO, 20 numbers are chosen randomly from the range of values
1 to 80 and displayed in a grid on a screen. Four rows and five columns are
used to display the 20 values. In the real KENO game, no duplicates are
allowed in these values, but for our modified game, duplicates are allowed,
making the code much easier to write.
In order to play KENO, the player must first decide whether he wants to try to
match only 1 of the 20 numbers, or 2, or more. The number of matches you
are trying to make is called the spot. So if the player wants to bet that
he can match 4 of the 20 numbers, it is said that he's playing a 4 spot game.
The player can choose to play a 1 spot game up to a 10 spot game.
Next the player must decide how much to wager. He can choose to bet between
$ 1 and $ 20 per game. The chart shown below will show the prize value per
dollar wagered.
Finally the player must choose the numbers he thinks will come up. Obviously,
if the player is playing a 3 spot game, he must enter 3 numbers; 7 spot game,
7 numbers, etc. In the real KENO game, if you are playing the 3 (or more)
spot game, you can win smaller prizes than those shown in the chart below for
matching fewer number than the spot of the game. In our modified version, the
player must match all 3 numbers to win a 3 spot game. The payouts are shown in
the chart below.
KENO Payout Chart
1 spot game match 1 to win $ 2 per $ 1 bet
2 spot game match 2 to win $ 10 per $ 1 bet
3 spot game match 3 to win $ 25 per $ 1 bet
4 spot game match 4 to win $ 50 per $ 1 bet
5 spot game match 5 to win $ 300 per $ 1 bet
6 spot game match 6 to win $ 1000 per $ 1 bet
7 spot game match 7 to win $ 2500 per $ 1 bet
8 spot game match 8 to win $ 10000 per $ 1 bet
9 spot game match 9 to win $ 25000 per $ 1 bet
10 spot game match 10 to win $ 100000 per $ 1 bet
The Task
You are to write a program that simulates the playing of KENO, using the
CMSC 201 modifications stated above. These modifications will make the
coding of the project easier.
You'll be expected to write a minimum of ten functions, other than
main, for this project.
Here are the function prototypes:
void DisplayRules (void);
int GetSeedFromUser (void);
int GetRandomNumber (int high, int low);
int GetSpots (void);
int GetWager (void);
void GetPicks (int picks[10], int spots);
void DrawNumbers (int numbers[4][5], int rows, int cols, int high,
int low);
void DisplayNumbers (int numbers[4][5], int rows, int cols);
int IsWinner (int numbers[4][5], int picks[10], int rows, int cols,
int spots);
void DisplayWinnings (int winner, int wager, int spots);
Function Descriptions:
- DisplayRules - should print a message to the user, explaining the game
and what the program will do. Since this function returns nothing, it can
also be called a procedure.
- GetSeedFromUser - This function will prompt the user for an integer and
return that integer to the calling function to be used as a seed for the
random number generator. You may NOT use a call to time to get a seed
for this project, since that makes it extremely difficult to grade.
- GetRandomNumber - Returns an integer in the range of low to high,
inclusively, to the calling function. You may use the code for this function
found in the lecture notes.
- GetSpots - This function gets an integer from the user in the range of
1 to 10 and returns that number to the calling function.
- GetWager - This function gets an integer from the user in the range of
1 to 20 and returns that number to the calling function. This is the amount
in dollars that the user wants to bet.
- GetPicks - This function takes an array called picks as an argument and
also the number of spots the user has chosen to play. This function must
prompt the user to enter each of the numbers he is betting will be in the
20 randomly chosen numbers. The user must enter the appropriate amount of
numbers for the spots he has chosen, i.e. he must pick 3 numbers if he is
playing the 3 spot game. The numbers that the player chooses are to be stored
in the array picks.
- DrawNumbers - This function takes the two-dimensional array called
numbers as an argument and also the number of rows and columns. DrawNumbers
is to call the function GetRandomNumber() 20 times, filling the array with
these values.
- DisplayNumbers - This function takes the array numbers as an argument,
as well as the rows and cols. As its name implies, this function will display
the values found in the array in a grid pattern with the variable rows
determining the number of rows in the grid and cols determining the number
of columns.
- IsWinner - This is a predicate function, meaning that it returns either
True or False (1 or 0). Each number in the array, picks, needs to be compared
to each of the values in the array, numbers. If one of the numbers chosen by
the user matches one of the values in the array numbers, then a counter should
be incremented. The player is only a winner if all of his picks are found
in the array numbers. The function should return 1 only if the count of
winning numbers equals the spots of the game.
- DisplayWinnings - This function should produce a message saying how much
you won. See the sample run.
Additional Coding Specifications
- The user should be allowed to continue to play until s/he enters the
sentinel value -1. All other integer values entered will require him play
again and also allow him to change the spots, wager and numbers picked for the
next game.
- Only seed the random number generator once, at the beginning of the
program, rather than for each drawing of numbers.
Further Clarification
- I guarantee that all of the input will be integers.
- I further guarantee that the player will never enter duplicates of a
number when making his choices for any single game. For example, if the
player chooses to play a 3-spot game, I guarantee that he will enter 3
different values for his three picks. Of course, he may try to enter a
value that is out of range and you must guard against this.
Extra Credit --- 5 points
For extra credit, you must have no duplicates among the 20 randomly chosen
numbers. This must be accomplished in an efficient manor or your work will
gain you no extra points. You may use any sorting or searching code that is
given either on the lecture pages or in your text, just cite your source.
Sample Output
[Game description and rules go here]
Please enter a number : 7
Enter how many numbers you want to play (1 - 10) :2
Make your wager in dollars (1 - 20) :1
Pick a number (1 - 80) :52
Pick a number (1 - 80) :21
45 47 69 35 52
6 35 31 66 34
14 4 31 35 30
3 26 55 31 21
You won $ 10
Enter any integer to continue playing, or -1 to end : 1
Enter how many numbers you want to play (1 - 10) :3
Make your wager in dollars (1 - 20) :10
Pick a number (1 - 80) :19
Pick a number (1 - 80) :11
Pick a number (1 - 80) :31
13 68 40 59 62
65 40 34 75 71
54 31 19 11 69
68 36 73 25 69
You won $ 250
Enter any integer to continue playing, or -1 to end : 5
Enter how many numbers you want to play (1 - 10) :5
Make your wager in dollars (1 - 20) :2
Pick a number (1 - 80) :17
Pick a number (1 - 80) :29
Pick a number (1 - 80) :49
Pick a number (1 - 80) :21
Pick a number (1 - 80) :5
56 79 29 46 47
47 47 65 11 34
18 80 14 60 34
15 67 36 21 39
You won $ 0
Enter any integer to continue playing, or -1 to end : 1
Enter how many numbers you want to play (1 - 10) :11
Invalid number - only numbers between 1 and 10
Enter how many numbers you want to play (1 - 10) :-1
Invalid number - only numbers between 1 and 10
Enter how many numbers you want to play (1 - 10) :1
Make your wager in dollars (1 - 20) :25
Invalid number - only numbers between 1 and 20
Make your wager in dollars (1 - 20) :0
Invalid number - only numbers between 1 and 20
Make your wager in dollars (1 - 20) :3
Pick a number (1 - 80) :49
78 15 22 25 5
18 17 57 59 4
45 38 1 53 45
26 11 1 5 38
You won $ 0
Enter any integer to continue playing, or -1 to end : -1
Thanks for playing KENO
Hope you didn't lose your shirt !!!
Submitting the Program
To submit the file you should use the command:
submit cs201 proj2 proj2.c keno.c keno.h
You can check your submission by using the command:
submitls cs201 proj2