Need help with $end vs kEND error

I have been trying to write a program for my class assignment but
everytime i do i get an error on the last line of the code that says
'unexpected $end, expecting kEND'
this happens on every program i try to run
any ideas?

i am using fedora core 5 if that makes a difference

···

--
Posted via http://www.ruby-forum.com/.

Kd Kushelduv wrote:

I have been trying to write a program for my class assignment but
everytime i do i get an error on the last line of the code that says
'unexpected $end, expecting kEND'
this happens on every program i try to run
any ideas?

i am using fedora core 5 if that makes a difference

Often times this error is a result of missing an end statement somewhere
within your program. For example, you may have forgotten to end a
method, if statement or class. Can you post some code so we can take a
look?

···

--
Posted via http://www.ruby-forum.com/\.

I'm just learning ruby myself, but typically when this
happens, I'm missing an end to a function, or some other
block:

#!/usr/bin/ruby

def joe
     print "JOE MAMMA\n"

Produces:

[alibby@localhost ~]$ ./t.rb
./t.rb:6: syntax error, unexpected $end, expecting kEND

Perhaps this is it? If you're willing to post the code (if it's not too long) we may be able to provide more guidance.

Andy

Kd Kushelduv wrote:

···

I have been trying to write a program for my class assignment but everytime i do i get an error on the last line of the code that says 'unexpected $end, expecting kEND'
this happens on every program i try to run
any ideas?

i am using fedora core 5 if that makes a difference

You have mismatched block openings / endings. Check your def / end
do / end if / end, etc...

···

On 10/10/06, Kd Kushelduv <kushelduv@mac.com> wrote:

I have been trying to write a program for my class assignment but
everytime i do i get an error on the last line of the code that says
'unexpected $end, expecting kEND'
this happens on every program i try to run
any ideas?

i am using fedora core 5 if that makes a difference

--
Posted via http://www.ruby-forum.com/\.

as far as i can tell nothing is missing
here is the code (its only three methods):

def promptToQuit
   print "\nYou did not enter any numbers \n are you sure you wish to
quit? (y/n): "
   answer = getc
   answer = answer.downcase
   while (answer != 'y' && answer != 'n')
      print "Are you sure you wish to quit? (y/n): "
      answer = getc
      answer = answer.downcase
   end

   return answer
end

def getNumbers (num)
   $high = num
   $low = num

   while (num != 0)
      print "Please enter a number (0 to quit): "
      num = geti

      if ( (num > $high) && (num != 0) ) then
         $high = num
      else if ( (num < $low) && (num != 0) ) then
         $low = num
      end
   end
end

answer = 'n'

print "\nPlease enter a number (0 to quit): "
num = geti

if (num == 0) then
   answer = promptToQuit
end

if (answer == 'y') then
   print "\nGoodbye"
else
   num = 1
   getNumbers(num)
end

puts "Highest Number: " + $high.to_s
puts "Lowest Number: " + $low.to_s
puts "\n"

···

--
Posted via http://www.ruby-forum.com/.

Kd Kushelduv wrote:

      if ( (num > $high) && (num != 0) ) then
         $high = num
      else if ( (num < $low) && (num != 0) ) then
         $low = num
      end

This should be

       if ( (num > $high) && (num != 0) ) then
          $high = num
       elsif ( (num < $low) && (num != 0) ) then
          $low = num
       end

Your else is starting a new block context (not the Ruby term I'm sure;
that's kinda what I'd call it in Perl :slight_smile: and Ruby thinks what you're
doing is:

if ...

else
  if ...
  end
end

But you've only got a single end so it's confuzzled.

···

--
Posted via http://www.ruby-forum.com/\.

as far as i can tell nothing is missing
here is the code (its only three methods):

def promptToQuit
   print "\nYou did not enter any numbers \n are you sure you wish to
quit? (y/n): "
   answer = getc
   answer = answer.downcase
   while (answer != 'y' && answer != 'n')
      print "Are you sure you wish to quit? (y/n): "
      answer = getc
      answer = answer.downcase
   end

   return answer
end

def getNumbers (num)
   $high = num
   $low = num

   while (num != 0)
      print "Please enter a number (0 to quit): "
      num = geti

      if ( (num > $high) && (num != 0) ) then
         $high = num
      else if ( (num < $low) && (num != 0) ) then
         $low = num

Right here. You want elsif, otherwise you are missing
the closing end for the nested if. Also, drop the thens,
they are not needed :slight_smile:

      end
   end
end

answer = 'n'

print "\nPlease enter a number (0 to quit): "
num = geti

if (num == 0) then
   answer = promptToQuit
end

if (answer == 'y') then
   print "\nGoodbye"
else
   num = 1
   getNumbers(num)
end

puts "Highest Number: " + $high.to_s
puts "Lowest Number: " + $low.to_s
puts "\n"

The error message is a bit ambiguous--$end means EOF, which
Ruby encountered while it was still waiting for a literal
end (the token is called kEND).

···

On 2006.10.11 03:23, Kd Kushelduv wrote:

huh that was the problem but my text book had everything as
elseif

i added the space because it wouldn't accept that
but it seems the author still mistyped the entire thing

o well

···

--
Posted via http://www.ruby-forum.com/.

Kd Kushelduv wrote:

huh that was the problem but my text book had everything as
elseif

i added the space because it wouldn't accept that
but it seems the author still mistyped the entire thing

Umm, just curious, who is the author, what is the book or article?

···

--
Paul Lutus
http://www.arachnoid.com