+ 1
How to take two variables as input by user, in one line with space?
I want to to take two variables input by user in one line with space. Ex. Input: 22 48 output: 22 48=70 Please help me. Thanks
5 Answers
+ 6
Tried doing it, I got a No Output at first I'll reply back when I found a way
+ 5
in python, you could split the string into a list. I dont know if this is possible in ruby though...
+ 5
@Huan Wang Doing good today :D Thanks, Its summer today so I dont have school anymore, code day everyday :D
+ 2
I give you a simple way:
puts "Please input some numbers: "
x = gets.chomp.split(" ")
puts x.inject(0) {|sum, ele| sum += ele.to_i}
You can input as many numbers as you want, enjoy!
+ 2
@MrCoder, how are you these days?