Write a program that lets the user play the slot machine (https://en.wikipedia.org/wiki/Slot_machine).
Write a program that lets the user play the slot machine (https://en.wikipedia.org/wiki/Slot_machine).
A slot machine features a screen displaying three or more reels. To play, the user inserts money and activates the machine by means of a lever or button (either physical or on a touchscreen). The reels then spin and stop to rearrange the symbols. If the rearranged symbols match a winning combination, the player earns points based on a pay table. Symbols vary depending on the theme of the machine. Classic symbols include objects such as fruits, bells, and stylized lucky sevens.
In this assignment, we slightly modify the operating mode of the slot machine as follows. Instead of the user manually activating the machine every time they want to play, the program will automatically play on behalf of the user multiple times. The user can choose from the following menu:
1-> Play n times. The machine will repeatedly play n times.
2-> Play until the credit gets below a minimum value. The machine will repeatedly play until the user's credit gets below a value specified by the user, or until it has played MAX_NUM_ITER times, whichever comes first. MAX_NUM_ITER is a parameter. Note that the user is allowed to set a positive or negative value.
3-> Play until the credit gets above a maximum value. The machine will repeatedly play until the user's credit gets above a value specified by the user, or until it has played MAX_NUM_ITER times, whichever comes first. MAX_NUM_ITER is a parameter. Note that the user is allowed to set a positive or negative value.
4-> Play until the credit gets above a maximum value or below a minimum value. The machine will repeatedly play until the user's credit gets above the max value or below the min value, which are specified by the user, or until it has played MAX_NUM_ITER times, whichever comes first. MAX_NUM_ITER is a parameter. Note that the user is allowed to set a positive or negative value for the max value and min value.
Regardless of the user's menu choice, every time the machine plays on behalf of the user, the user's credit is updated according to the pay table below.
Possible symbols are "Orange", "Strawberry", "Plum", "Watermelon", "Lemon", "Cherry".
A winning combination is a combination where all three reels display the same symbol. The points earned depends on the symbol.
At each play, PLAY_FEE is deducted from the credit. In addition, if the play results in a winning combination, the corresponding points are added to the credit.
Three "Orange" : 100 points
Three "Strawberry" : 200 points
Three "Plum": 300 points
Three "Watermelon" : 400 points
Three "Lemon": 500 points
Three "Cherry": 1000 points
The credit and PLAY_FEE should be double.
Set MAX_NUM_ITER and PLAY_FEE to 100 and 0.25 respectively.
Identify each symbol by an int ranging from 0 to 5.
Use an array of three ints to represent the reels. For example, if reel is the array, reel[0] = 0, reel[1] = 3, reel[2] = 5, means the reels are "Orange", "Watermelon" and "Cherry" respectively.
To spin a reel, use rand() with the appropriate scaling and shifting to generate a random value between 0 and 5.
If the user chooses 1, the program should prompt the user for n. If the user chooses 2 or 3, the program should prompt the user for the minimum or maximum value. If the user chooses 4, the program should prompt the user for the minimum and maximum value.
Throughout the execution, the program should keep track of the highest value of the credit (high-water mark) and lowest value of the credit (low-water mark) so far, and print these values at the end.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images