+ 3
What is the problem with this code
look at this ruby code and tell me what is the problem age =gets() if (age >18) then print "you are major " end when i execute this code there are error why ??
4 Answers
+ 2
that way ??:
age = gets.chomp()
if (age. to_i > 18) then
print "you are major "
end
is it correct??
+ 2
it don't work
look at
age = gets.chomp()
if (age. to_i > 18) then
print "you are major "
end
they say no output
+ 1
age is being treated as a string
To use it as an integer you have to:
1. Remove newline character
For this use gets.chomp() instead of gets()
2. Convert to integer
Do age.to_i to use as integer
0
Should be.
Just as a remark you don't need the 'then'



