Question

This needs to be done using c++ No vectors or arrays can be used since we...

This needs to be done using c++

No vectors or arrays can be used since we haven't learned them yet!

Write a program that simulates a slot machine. The slot machine should have the following characteristics:

- 3 view windows to display items on a wheel. Typically, these are cherries, bars, etc.

- each wheel will randomly select a number 1-7.

- the user will be charged 5 tokens to spin the wheels

Winning combinations will be as follows:

- JACKPOT will consist of 7, 7, 7. The user will win 500 tokens.

- TRIPLE will consist of any other combination (1-6) where all numbers match. The user will win 100 tokens.

- STRAIGHT will consist of any "in-order run". For example: 1, 2, 3 or 3, 4, 5… The user will win 50 tokens.

- DOUBLE will consist of any matching pair. For example: 1, 2, 1 or 3, 4, 4 … The user will win 3 tokens.

General algorithm: To start the game, the user will input a specific integer to initialize the random number generator. This is to allow the test cases to create duplicate output.

srand( randomInit ); // randomInit is an integer variable, input by the user

The user will then enter the number of tokens to begin. This will simulate banking/inserting money into the slot machine.

If the user has enough tokens, begin the game by subtracting the number of tokens to play the game from the users bank.

The slot machine will spin the wheels by generating 3 random numbers. Display the numbers.

Determine if the 3 random numbers are a winning combination. Display a message if the user wins or loses (see below). If the user wins, add the appropriate amount of tokens to the users bank.

If the user has enough tokens, they will be asked to play again (y/n). If the user has enough tokens and they want to play again, repeat the game. If the user does not have enough tokens to play, they should not be prompted to play again. An error message should be displayed: Sorry, you need 5 tokens to play. and the game ends.

Display a message at the end of the game to show it completed successfully. Thank you for playing. Come again.

Sample Input:

30000 100 y y y y n

Sample Output:

*5* *3* *3*

***************

* DOUBLE!! *

***************

You have 98 tokens.

*5* *1* *7*

***LOSER!!***

You have 93 tokens.

*2* *3* *4*

***************

* STRAIGHT!! *

***************

You have 138 tokens.

*1* *3* *5*

***LOSER!!***

You have 133 tokens.

*2* *6* *6*

***************

* DOUBLE!! *

***************

You have 131 tokens.

Thank you for playing. Come again.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

using namespace std;

int main(){

// declaring constants and variables
int randomInit; //seed
int balance; //tokens
int charge = 5; //tokens charged per play
int x_min = 1,x_max = 7; // range of targets
int x1,x2,x3; // targets from different spins
char play='n'; // decision variable to play or not

// user input for seed of random generator
cout<<endl<<"Enter any integer: "; cin>>randomInit;
srand(randomInit);

// depositing tokens
cout<<endl<<"Enter number of tokens (minimum 5): "; cin>>balance;

do
{
balance = balance - charge;

// generating 3 random integers (targets) x1,x2,x3 between x_min and x_max
x1 = x_min + (rand() %7+1 / (x_max-x_min+1));
x2 = x_min + (rand() %7+1 / (x_max-x_min+1));
x3 = x_min + (rand() %7+1 / (x_max-x_min+1));

// displaying the targets scored
cout<<"*"<<x1<<"**"<<x2<<"**"<<x3<<"*"<<endl;

// determining the earnings according to target scores
if(x1==7 && x1==x2 && x2==x3){
cout<<"******JACKPOT!!!!!!*******"<<endl;
cout<<"*********************"<<endl;
balance = balance + 500;
}else if(x1==x2 && x2==x3){
cout<<"******TRIPLE!!!*******"<<endl;
cout<<"*********************"<<endl;
balance = balance + 100;
}else if((x2-x1)==1 && (x3-x2)==1){
cout<<"******STRAIGHT!!*****"<<endl;
cout<<"*********************"<<endl;
balance = balance + 50;
}else if(x1==x2 || x1==x3 || x2==x3){
cout<<"******DOUBLE!*******"<<endl;
cout<<"*********************"<<endl;
balance = balance + 3;
}else{
cout<<"LOSER!"<<endl;
}

// displaying current token balance
cout<<"You have "<<balance<<" tokens"<<endl;

// deciding the continuity of the game after earnings and charges
if (balance>=charge){
cout<<endl<<"Play again? (y/n): ";cin>>play;
}else{
cout<<endl<<"Sorry, you need 5 tokens to play"<<endl;
play = 'n'; // terminate the loop
}
cout<<endl;
}while(play=='y');

cout<<"Thank you for playing. Come again"<<endl;

return 0;
}

------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,

IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~

Add a comment
Know the answer?
Add Answer to:
This needs to be done using c++ No vectors or arrays can be used since we...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Craps

    Write a C++ game that plays Craps. Craps is a game played with a pair of dice. The shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the ‘come out roll’) is a 7 or 11, the shooter wins the game. If the opening roll results in a 2 (snake eyes), 3 or 12 (box cars), the shooter loses,...

  • Binomial Probabilities: Suppose you go on a trip to Las Vegas. You stop at a slot...

    Binomial Probabilities: Suppose you go on a trip to Las Vegas. You stop at a slot machine where there is a 0.008 probability of winning the jackpot on a single turn. You decide to play the slot machine 2,000 times.   For each problem, circle the appropriate numbers on the number line, then calculate the probability and round all answers to 4 decimals.   Make sure you write down what you entered into the calculator. A. P(win exactly four times) = _________________         ...

  • 3) James made a game that costs $5 to play and stafames noticed the letter die. If HEADS you try to get a 1,3, or c...

    3) James made a game that costs $5 to play and stafames noticed the letter die. If HEADS you try to get a 1,3, or common. If tails you try to get a 2 ora because they start with the letter T. His logic is ads and 1,3, or 5 you win $10; heads and the others outcomes is tals with 2 or 3 wins $20 and tails with the other outcomes e dollar amount because he doesn't know money...

  • In C... Write a program to simulate a pick-5 lottery game. Your program must generate and...

    In C... Write a program to simulate a pick-5 lottery game. Your program must generate and store 5 distinct random numbers between 1 and 9 (inclusive) in an array. The program prompts the user for: an integer random seed five distinct integers between 1 and 9 (which are stored in another array) The program then compares the two arrays to determine if they are identical. If the two arrays are identical, then the user wins the game. otherwise the program...

  • Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game...

    Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game in Python 3 that a user plays against the computer with the ability to save and load a game and its associated play statistics. Purpose: The purpose of this challenge is to assess the developer’s ability to create an interactive application with data persistence in Python 3. Requirements: Create a Rock, Paper, Scissors game in Python named rps.py according to the requirements specified in...

  • HTML/CSS/Javascript Slot Machine How would you implement a slot machine where we have three slots with...

    HTML/CSS/Javascript Slot Machine How would you implement a slot machine where we have three slots with 7 images? You have a spin function so the slots randomizes. You also start off with $50 and can bet fron $1 $5 or $10. If the user wins then the earnings will be: 15*betAmount.

  • In C program #include<stdio.h> Write a program to simulate a pick-5 lottery game. Your program must...

    In C program #include<stdio.h> Write a program to simulate a pick-5 lottery game. Your program must generate and store 5 distinct random numbers between 1 and 9 (inclusive) in an array. The program prompts the user for: an integer random seed five distinct integers between 1 and 9 (which are stored in another array) The program then compares the two arrays to determine if they are identical. If the two arrays are identical, then the user wins the game. otherwise...

  • C# Code: Write the code that simulates the gambling game of craps. To play the game,...

    C# Code: Write the code that simulates the gambling game of craps. To play the game, a player rolls a pair of dice (2 die). After the dice come to rest, the sum of the faces of the 2 die is calculated. If the sum is 7 or 11 on the first throw, the player wins and the game is over. If the sum is 2, 3, or 12 on the first throw, the player loses and the game is...

  • In the game of Lucky Sevens, the player rolls a pair of dice. If the dots...

    In the game of Lucky Sevens, the player rolls a pair of dice. If the dots add up to 7, the player wins $4; otherwise, the player loses $1. Suppose that, to entice the gullible, a casino tells players that there are many ways to win: (1, 6), (2, 5), and soon. A little mathematical analysis reveals that there are not enough ways to win to make the game worthwhile; however, because many people's eyes glaze over at the first...

  • NEED LAST 2 Two individuals, A and B, are finalists for a chess championship. They will...

    NEED LAST 2 Two individuals, A and B, are finalists for a chess championship. They will play a sequence of games, each of which can result in a win for A, a win for B, or a draw. Suppose that the outcomes of successive games are independent, with P(A wins game) = 0.3, P(B wins game) = 0.2, and P(draw) = 0.5. Each time a player wins a game, he earns 1 point and his opponent earns no points. The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT