Note that there are some explanatory texts on larger screens.

plurals
  1. POProgramming Ruby Slot Machine Game
    primarykey
    data
    text
    <p>I'm trying to make a slot machine game in Ruby and this is as far as I've gotten. It still won't run and says there is an error on the last line, which I do not know what is or how to fix it. </p> <p>I need it to have an output similar to this:</p> <blockquote> <p>How much total money would you like to play with today? 25<br> Total cash: $ 25<br> How much would you like to bet? 10<br> Cherry - Orange - Orange<br> You have won $ 20<br> Would you like to continue? (yes to continue) yes<br> Total cash: $ 35<br> How much would you like to bet? etc…</p> </blockquote> <p>I've already got the winnings set on there, like if you get two, you win twice your bet and if you get three, you win three times your bet. </p> <p>But I get the error: <code>33: syntax error, unexpected $end, expecting kEND cash += cash + winnings</code></p> <p>What is wrong with my code, and how do I fix it?</p> <pre><code> def multiplier(s1, s2, s3) if s1 == s2 and s2 == s3: multiplier = 3 elsif s1 == s2 or s2 == s3 or s1 == s3: multiplier = 2 else multiplier = 0; return multiplier def main() slotImageList = ['Cherry', 'Orange', 'Plum', 'Bell', 'Melon', 'Bar'] cash = gets puts "How much total money would you like to play with today? " +cash while True: puts("Total cash: $", cash) bet = gets puts "How much would you like to bet? " +bet cash = (cash - bet) slotImage1 = slotImageList.sample slotImage2 = slotImageList.sample slotImage3 = slotImageList.sample puts "slotImage1", " - ", "slotImage2", " - ", "slotImage3" winnings = bet * multiplier(slotImage1, slotImage2, slotImage3) puts "You have won $" +winnings cash = cash + winnings cont = gets puts "Would you like to continue? (yes to continue) " +cont if cont != "yes": puts "You have ended with $" +cash else puts " " end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload