Question

In: Computer Science

With C language A slot machine has three windows. A random fruit is picked for each...

With C language

A slot machine has three windows. A random fruit is picked for each window from cherry, apple, lemon, and orange. If all three windows match, the user wins 8 times the bet amount. If the first two windows only are cherries, the user wins 3 times the bet amount. If the first window is a cherry and the second window is not a cherry, the user wins the bet amount. Otherwise, the player loses their bet. Write a C program that will first allow the user to enter a bet amount. Next, the program should pick 3 random fruits for the 3 windows and print the 3 fruits picked. Lastly, the amount of money won or lost by the user should be displayed.

Solutions

Expert Solution

Here we map the fruit with the numbers.

We map cherry with number 0

We map apple with number 1

We map lemon with number 2

We map orange with number 3

We map cherry with number 0

and then generates random number from 0 to 3 for all the three windows.

Here is the C-program

#include<stdio.h>
#include<stdlib.h> //for rand() function
#include<time.h> //for time() function

int main()
{
        int betAmount, window1, window2, window3, wonAmount;

        //INPUT BET AMOUNT FROM USER
        printf("Enter the bet amount ");
        scanf("%d", &betAmount);

        //GENERATING RANDOM NUMBER FROM 0 TO 3 FOR THREE WINDOWS
        srand(time(0));
        window1 = rand() % 4;
        window2 = rand() % 4;
        window3 = rand() % 4;

        //PRINTING THE FRUIT PICKED FOR FIRST WINDOW
        if(window1 == 0)
                printf("\n\nFruit picked for window 1 - CHERRY\n");
        else if(window1 == 1)
                printf("\n\nFruit picked for window 1 - APPLE\n");
        else if(window1 == 2)
                printf("\n\nFruit picked for window 1 - LEMON\n");
        else if(window1 == 3)
                printf("\n\nFruit picked for window 1 - ORANGE\n");

        //PRINTING THE FRUIT PICKED FOR SECOND WINDOW
        if(window2 == 0)
                printf("Fruit picked for window 2 - CHERRY\n");
        else if(window2 == 1)
                printf("Fruit picked for window 2 - APPLE\n");
        else if(window2 == 2)
                printf("Fruit picked for window 2 - LEMON\n");
        else if(window2 == 3)
                printf("Fruit picked for window 2 - ORANGE\n");

        //PRINTING THE FRUIT PICKED FOR THIRD WINDOW
        if(window3 == 0)
                printf("Fruit picked for window 3 - CHERRY\n");
        else if(window3 == 1)
                printf("Fruit picked for window 3 - APPLE\n");
        else if(window3 == 2)
                printf("Fruit picked for window 3 - LEMON\n");
        else if(window3 == 3)
                printf("Fruit picked for window 3 - ORANGE\n");

        //ALL THREE WINDOWS ARE MATCHED
        if(window1 == window2 && window2 == window3)
        {
                wonAmount = 8*betAmount;
                printf("\n\nPlayer wins 8 times the bet amount\n");
                printf("Amount of money won by user = %d\n", wonAmount);
        }

        //FIRST TWO WINDOWS ARE CHERRY
        else if(window1 == 0 && window2 == 0)
        {
                wonAmount = 3*betAmount;
                printf("\n\nPlayer wins 3 times the bet amount\n");
                printf("Amount of money won by user = %d\n", wonAmount);
        }

        //FIRST WINDOW IS CHERRY AND SECOND IS NOT CHERRY
        else if(window1 == 0 && window2 != 0)
        {
                wonAmount = betAmount;
                printf("\n\nPlayer wins the bet amount\n");
                printf("Amount of money won by user = %d\n", wonAmount);
        }
        else
        {
                printf("\n\nPlayer loses the bet\n");
                printf("Amount of money loses by user = %d\n", betAmount);
        }

}

PLEASE UPVOTE IF YOU LIKED THE ANSWER


Related Solutions

With C language A slot machine has three windows. A random fruit is picked for each...
With C language A slot machine has three windows. A random fruit is picked for each window from cherry, apple, lemon, and orange. If all three windows match, the user wins 8 times the bet amount. If the first two windows only are cherries, the user wins 3 times the bet amount. If the first window is a cherry and the second window is not a cherry, the user wins the bet amount. Otherwise, the player loses their bet. Write...
A slot machine has 3 wheels; each wheel has 20 symbols; the three wheels are independent...
A slot machine has 3 wheels; each wheel has 20 symbols; the three wheels are independent of each other. Suppose that the middle wheel has 11 cherries among its 20 symbols, and the left and right wheels have 2 cherries each.    a. You win the jackpot if all three wheels show cherries. What is the probability of winning the jackpot? b. What is the probability that the wheels stop with exactly 2 cherries showing among them?
A slot machine has 3 wheels; each wheel has 20 symbols; the three wheels are independent...
A slot machine has 3 wheels; each wheel has 20 symbols; the three wheels are independent of each other. Suppose that the middle wheel has 11 cherries among its 20 symbols, and the left and right wheels have 2 cherries each.    a. You win the jackpot if all three wheels show cherries. What is the probability of winning the jackpot? b. What is the probability that the wheels stop with exactly 2 cherries showing among them?
A slot machine has 5 reels each with 9 symbols one of which is a Jackpot....
A slot machine has 5 reels each with 9 symbols one of which is a Jackpot. How many different outcomes will occur after one spin? What is the possibility of atleast one jackpot? What is the possibility of no jackpots? What is the possibility of 3 jackpots?
QUESTION 19 A standard slot machine like this one (link) has three wheels that turn independently...
QUESTION 19 A standard slot machine like this one (link) has three wheels that turn independently with various symbols on them. Almost all slot machines now are controlled by computers that generate random numbers corresponding to certain winning and losing combinations of symbols. In the early days of slot machines, pulling the lever or "arm" to start spinning the wheels actually allowed the gambler to interact with the mechanics of the machine (thereby opening the door to all kinds of...
The language is MATLAB Write a function that will generate three random integers, each in the...
The language is MATLAB Write a function that will generate three random integers, each in the inclusive range from 10 to 80. It will then return a string consisting of the three integers joined together, and also a character vector consisting of the three integers joined together. For example, if the random integers are 11, 29, and 76, the string that is returned will be "112976" and the character vector that is returned will be '112976'. I'm really confused on...
A slot machine have an enterprise of 5$, it has four slots that generates numbers between...
A slot machine have an enterprise of 5$, it has four slots that generates numbers between number 1 and 5. If all the slots generates 5, you win 100$. If three of the slots generates 4, you win 20$. If two of the slots generates 3, or 2, you win 2$. Otherwise, you win x$. What is the smallest number that boss can set in order to profit on average?
*Answer must be in C++ and please use a Windows machine NOT IOS! Write a program...
*Answer must be in C++ and please use a Windows machine NOT IOS! Write a program as follows: Ask the user for an integer representing a number of integers to be sorted. Create an array of integers of the size provided by user. Initialize the array to zeros. Ask the user for and populate the array with user input. Output the array elements on one line separated by a space. Write a function name “supersort” that takes an integer pointer...
Code in C++ programming language description about chose favorite fruit and wage color of fruit in lesson Class object (Multiple class).
Code in C++ programming language description about chose favorite fruit and wage  color of fruit in lesson Class object (Multiple class).
Problem 1 Slot machines have three drums with the same number of positions on each drum....
Problem 1 Slot machines have three drums with the same number of positions on each drum. Each position contains a symbol. When you pull the lever on the machine, the drums spin. Assume that each drum is equally likely to stop in any position, and that the positions in which the three drums stop are independent of each other and independent from spin to spin. Suppose a particular slot machine has 9 positions on each drum, and that each position...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT