+ 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 ??

20th Apr 2017, 1:11 PM
timmy turner
timmy turner - avatar
4 Answers
+ 2
that way ??: age = gets.chomp() if (age. to_i > 18) then print "you are major " end is it correct??
20th Apr 2017, 1:21 PM
timmy turner
timmy turner - avatar
+ 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
20th Apr 2017, 1:52 PM
timmy turner
timmy turner - avatar
+ 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
20th Apr 2017, 1:15 PM
spcan
spcan - avatar
0
Should be. Just as a remark you don't need the 'then'
20th Apr 2017, 1:48 PM
spcan
spcan - avatar