Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Ruby program to simulate a roulette wheel and determine if one can doubl

ID: 3751880 • Letter: W

Question

Write a Ruby program to simulate a roulette wheel and determine if one can double their money

by doubling up on their losing bets.

On a roulette wheel (using the double

zero layout)

there are

38 slots for the ball to fall in.

18 are colored black, 18 are colored red, and 2 are colored green.

If

you bet on red or black, the payoff is 1 to 1, but the odds are slightly less than 50% (which is how

the house makes money).

Below is a pi

cture of a standard double

zero wheel:

Your goal is to write a ruby program that simulates the spining

of a roulette wheel (for which you

will use a random generator), the betting on one color, and the decision of where there is a payoff

or not.

You will also simulate the double of the losing bet, and resetting back to the base bet after

winning. You also

need to keep track of the total amount of money you have (which will call your

bank) to determine if you

can make the next bet or not.

Then you want to see if you can double

your bank of

money by using this strategy.

You also need to have the correct odds

(the correct

number of slots and correct color) as well as the correct pay off.

When you lose, you lose your

bet.

When you win, you keep your bet, plus earn the same as your bet (i.e. double your bet).

Explanation / Answer

val1 = gets.to_i sym = gets.chomp val2 = gets.to_i def addition(val1, val2) return val1+val2 end add = addition(val1, val2) def subtraction(val1, val2) return val1-val2 end sub = subtraction(val1, val2) def division(val1, val2) return val1/val2 end div = division(val1, val2) def multiplication(val1, val2) return val1*val2 end mult = multiplication(val1, val2) if sym == "+" puts add elsif sym == "-" puts sub elsif sym == "/" puts div elsif sym == "*" puts mult else puts "error" end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote