Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7878029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:32:40+00:00 2026-06-03T03:32:40+00:00

I’m trying to make a slot machine game in Ruby and this is as

  • 0

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.

I need it to have an output similar to this:

How much total money would you like to play with today? 25
Total cash: $ 25
How much would you like to bet? 10
Cherry – Orange – Orange
You have won $ 20
Would you like to continue? (yes to continue) yes
Total cash: $ 35
How much would you like to bet?
etc…

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.

But I get the error: 33: syntax error, unexpected $end, expecting kEND cash += cash + winnings

What is wrong with my code, and how do I fix it?

    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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:32:43+00:00Added an answer on June 3, 2026 at 3:32 am

    When you see the message:

    unexpected $end, expecting kEND

    you can translate it to, “I reached the end-of-file (“$end”), but I did not expect it, because I was still waiting to see an end statement.” It means that you forgot to type at least one paired end, and you need to go through your code and ensure that it’s indented properly so that you can visually match up the statements.

    Below is the result of fixing your code to be correct.; in some spots you seemed to have used indentation to close a block (like Python) instead of the correct syntax.

    def multiplier(s1, s2, s3)
      if s1==s2 && s2==s3
        3
      elsif s1==s2 || s2==s3 || s1==s3
        2
      else
        0
      end
    end
    
    def run_slots!
      slotImageList = %w[Cherry Orange Plum Bell Melon Bar]
    
      print "How much total money would you like to play with today? "
      cash = gets.chomp.to_i
      loop do
        puts "Total cash:  $#{cash}"
        print "How much would you like to bet? "
        bet = gets.chomp.to_i
    
        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 += winnings
    
        print "Would you like to continue? (yes to continue) "
        unless gets.chomp=="yes"
          puts "You have ended with $#{cash}"
          break
        end
      end
    end
    
    run_slots! if __FILE__==$0
    

    If I were to take a few more liberties with it, here’s how I might write it:

    class SlotGame
      SLOT_COUNT = 3
      TOKENS     = %w[Cherry Orange Plum Bell Melon Bar]
      KEEP_PLAYING_RESPONSES = %w[y yes sure ok go]
    
      def initialize(cash=nil)
        unless cash
          begin
            print "How much total money would you like to play with today? "
            cash = gets.to_i
            puts "You must have a positive bank account to play!" if cash<=0
          end until cash > 0
        end
        @cash = cash
      end
    
      def play_forever
        begin
          # Using begin/end ensures one turn will be played
          # before asking the player if they want to go on
          play_one_turn
        end while @cash>0 && keep_playing?
        puts "You have ended with $#{@cash}; goodbye!"
      end
    
      def play_one_turn
        puts "Total cash: $#{@cash}"
    
        begin
          print "How much would you like to bet? "
          bet = gets.to_i
          puts "You only have $#{@cash}!" if bet > @cash
        end until bet <= @cash
        @cash -= bet
    
        results = SLOT_COUNT.times.map{ TOKENS.sample }
        puts results.join(' - ')
        winnings = bet * multiplier(results)
    
        if winnings>0
          @cash += winnings
          puts "You just won $#{winnings}!"
        else
          puts "Sorry, you're not a winner."
        end
      end
    
      def keep_playing?
        print "Would you like to continue? "
        KEEP_PLAYING_RESPONSES.include?(gets.chomp.downcase)
      end
    
      private # Don't let anyone outside run our magic formula!
        def multiplier(*tokens)
          case tokens.flatten.uniq.length
            when 1 then 3
            when 2 then 2
            else 0
          end
        end
    end
    
    SlotGame.new.play_forever if __FILE__==$0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.