I have this function:
def func()
puts "Give a value for x \n>"
x = gets.chomp
puts "Give a value for y \n>"
y = gets.chomp
z = x + y
puts z
end
If a user inputs 5 for x and 5 for y, I want z to make 5 + 5 and print 10, but this will print 55 instead.
The values you’ve read are stored as strings, and with strings, the
+operator performs concatenation. You need to convert both inputs to integers if you want to perform integer arithmetic: