A slot machine has three windows. A random fruit is picked for each window from
ID: 3911811 • Letter: A
Question
A slot machine has three windows. A random fruit is picked for each window from cherry and orange. If all three windows match, the user wins 8 times the bet amount. If the first two the first window is a cherry and the is not a cherry, the user wins the bet amount Otherwise, the player loses their bet Write Proaram4? apple, lemon, windows only are cherries, the user wins 3 times the bet amount. If second window a C program that will first allow the user to enter a bet amount. Next, the program s for the 3 windows and print the 3 fruits picked. Lastly, t hould pick 3 random the amount of money won or lost by the user should beExplanation / Answer
Below is the solution:
code:
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main ()
{
srand (time(NULL)); //initialize the random seed
int betAmount; //variable beta amount
string fruit [] = {"cherry", "apple", "lemon", "orange"}; //array of string fruit
string fruit1[3]; //string array that store the random picked 3 fruit
cout<<"Enter Bet Amount: "; //enter bet amount
cin>>betAmount; //store in betAmount
cout<<"You Get: ";
for(int i=0;i<3;i++){ //random generate the four int and put it in string array three times
int fruitRandom = rand() % 4;
cout << fruit[fruitRandom]<<" "; //display random picked fruit
fruit1[i]=fruit[fruitRandom]; //store in fruit1 random array
}
cout<<endl;
if(fruit1[0]=="cherry" && fruit1[1]=="cherry" && fruit1[2]=="cherry"){ //if all the three random picked fruit is cherry
cout<<"Winning Amount:"<<betAmount*8; //wins 8 times bet amount
}
else if(fruit1[0]=="apple" && fruit1[1]=="apple" && fruit1[2]=="apple"){ //if all the three random picked fruit is apple
cout<<"Winning Amount:"<<betAmount*8; //wins 8 times bet amount
}
else if(fruit1[0]=="lemon" && fruit1[1]=="lemon" && fruit1[2]=="lemon"){ //if all the three random picked fruit is lemon
cout<<"Winning Amount:"<<betAmount*8; //wins 8 times bet amount
}
else if(fruit1[0]=="orange" && fruit1[1]=="orange" && fruit1[2]=="orange"){ //if all the three random picked fruit is orange
cout<<"Winning Amount:"<<betAmount*8; //wins 8 times bet amount
}
else if(fruit1[0]=="cherry" && fruit1[1]=="cherry"){ //if first two fruit is cherry
cout<<"Winning Amount:"<<betAmount*3; //wins 3 times bet amount
}
else if(fruit1[0]=="cherry"){ //if first fruit is cherry
cout<<"Winning Amount:"<<betAmount; //wins only bet amount
}
else{ //otherwise loose their bet amount
cout<<"Oh! Loose";
}
return 0;
}
sample output:
Enter Bet Amount: 20
You Get: cherry orange orange
Winning Amount:20
Enter Bet Amount: 20
You Get: lemon orange orange
Oh! Loose
Enter Bet Amount: 20
You Get: orange orange apple
Oh! Loose
Enter Bet Amount: 20
You Get: cherry lemon lemon
Winning Amount:20
Enter Bet Amount: 20
You Get: lemon apple lemon
Oh! Loose
Enter Bet Amount: 20
You Get: lemon orange apple
Oh! Loose
Enter Bet Amount: 20
You Get: cherry cherry orange
Winning Amount:60
Enter Bet Amount: 20
You Get: cherry cherry cherry
Winning Amount:160
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.