Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you see the message:</p> <blockquote> <p>unexpected $end, expecting kEND</p> </blockquote> <p>you can translate it to, <em>"I reached the end-of-file ("$end"), but I did not expect it, because I was still waiting to see an <code>end</code> statement."</em> It means that you forgot to type at least one paired <code>end</code>, and you need to go through your code and ensure that it's indented properly so that you can visually match up the statements.</p> <p>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.</p> <pre><code>def multiplier(s1, s2, s3) if s1==s2 &amp;&amp; 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 </code></pre> <p>If I were to take a few more liberties with it, here's how I might write it:</p> <pre><code>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&lt;=0 end until cash &gt; 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&gt;0 &amp;&amp; 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 &gt; @cash end until bet &lt;= @cash @cash -= bet results = SLOT_COUNT.times.map{ TOKENS.sample } puts results.join(' - ') winnings = bet * multiplier(results) if winnings&gt;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 </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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