Why doesn't this code work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why doesn't this code work?

x=gets puts x+10 I try to type in a number to add to 10 and it returns an error edit: oh I see thank you guys. What is the purpose of having strings separate in the first place?

14th May 2017, 3:21 AM
AJ Sellarole
AJ Sellarole - avatar
3 Answers
+ 3
because the input you get with "gets" is a string even if it is a number. you need to convert your string to an integer x = gets.to_i puts x+10
14th May 2017, 3:29 AM
CHMD
CHMD - avatar
+ 8
The variable x is a string data type by default try this, this will surely work: x = gets.to_i puts x+10
14th May 2017, 3:29 AM
Complex
Complex - avatar
+ 2
xD
14th May 2017, 3:29 AM
CHMD
CHMD - avatar