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 is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>

int main(){
        //seeding random number generator with time
        srand(time(NULL));
        
        int bet;
        //asking, reading bet amount
        printf("Enter the bet amount (integer): ");
        scanf("%d",&bet);
        
        //creating an array of 4 fruits
        const char* choices[]={"cherry","apple","lemon","orange"};
        
        //choosing random fruits for three windows
        //(generating an index between 0 and 3, taking that value from choices array, storing in each
        //window)
        const char* window1=choices[rand()%4];
        const char* window2=choices[rand()%4];
        const char* window3=choices[rand()%4];
        
        //displaying picked fruits for each window
        printf("\nFruits picked: %s - %s - %s\n\n",window1,window2,window3);
        
        //checking if all three windows have same fruit
        if(strcmp(window1,window2)==0 && strcmp(window2,window3)==0){
                printf("all three windows match, you won %d!\n",bet*8); //8x
        }
        //otherwise checking if first two windows are cherries
        else if(strcmp(window1,"cherry")==0 && strcmp(window2,"cherry")==0){
                printf("first two windows are cherries, you won %d!\n",bet*3); //3x
        }
        //otherwise checking if first window has cherry
        else if(strcmp(window1,"cherry")==0 && strcmp(window2,"cherry")!=0){
                printf("first window is a cherry and the second window is not a cherry, you won %d!\n",bet); //1x
        }
        //otherwise lost.
        else{
                printf("Sorry! You lose!\n");
        }
        return 0;       
}

/*OUTPUT (different runs)*/

Enter the bet amount (integer): 10

Fruits picked: cherry - cherry - orange

first two windows are cherries, you won 30!

Enter the bet amount (integer): 5

Fruits picked: cherry - apple - apple

first window is a cherry and the second window is not a cherry, you won 5!

Enter the bet amount (integer): 10

Fruits picked: cherry - cherry - cherry

all three windows match, you won 80!
Enter the bet amount (integer): 20

Fruits picked: apple - cherry - lemon

Sorry! You lose!

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