Major Argument Problem

So I was working on my program which is suppose to ask the user to enter
an integer and the program is suppose to return odd or even depending on
that integer. I am new to coding and the below code is what I came up
with but its not working at all. I am using eclipse not the IRB. If
anyone would like to steer me in the right direction in a basic text
format would be helpful.

puts “input an integer value”

num1 = STDIN.gets
num1.chop!
num1 = num1.to_i
if
num1 0> 1.even?
false
puts “odd”
else
if
num 0> 2.even?
true
puts “even”
end
end

$ ruby -e ’
puts “input an integer value”

num1 = STDIN.gets
num1.chop!
num1 = num1.to_i
if
num1 0> 1.even?
false
puts “odd”
else
if
num 0> 2.even?
true
puts “even”
end
end

input an integer value
123
-e:8:in >': comparison of Fixnum with false failed (ArgumentError) from -e:8:in

Your use of “true” and “false” constants does not make sense. What
where you trying to achieve with that? Why don’t you just evaluate the
result of num1.even? or num1.odd? ?

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