Expecting kEND

I know this is a literal translation to keyword end, but unsure
sometimes (right now that is frequent) of where end goes. I know
there is one to end the method definition.
However adding one after the if and one after the else , or just one
for both conditions doesn’t seem to help.

def roman num

if num <= 4
i = 1
rn = (num/i)
rn.times do
print “I”

else num >= 5 && num <= 9
v = 5
rn = (num/v)
rnm = (num%v)
rn.times do
print “V”
rnm.times do
print “I”

end

Also your else should be elsif, assuming you only want that piece of
code to execute when num >= 5 && num <= 9

You need matching ends for def, if and do…

def roman num

if num <= 4
i = 1
rn = (num/i)
rn.times do
print “I”
end

else num >= 5 && num <= 9
v = 5
rn = (num/v)
rnm = (num%v)
rn.times do
print “V”
end
rnm.times do
print “I”
end
end

end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs