+ 3

How to make it work? Help plz.

I want to take two numbers from user and simply count them like 2+2. What's wrong? Sorry, I didn't managed to find this primitive thing. a = gets b = gets.chomp puts a+b

16th Nov 2017, 6:11 PM
Ynellaras
Ynellaras - avatar
9 Antworten
+ 3
Yea, if you use .to_s or if you just leave it as it is, it'll try to use it as a string instead of as numbers. .to_i converts it to an integer so you can do calculations on it. No need to feel dumb! Most people are here to learn, so no worries! As they say, the only dumb questions are the questions never asked. I've been messing around with programming for what feels like forever, so don't feel bad because you're learning, ALL of us were at that point before also. Don't forget, we're here to help you, so ask away when you have questions. Also, you're more than welcome bro. I wish the best for you and your learning!
16th Nov 2017, 6:30 PM
AgentSmith
+ 3
This is the first time I've ever read or coded with Ruby, so there may be people here that can better assist you. However, I played around with it and figured out what you're wanting to do. I also found a language that I may hate more than Python. lol https://code.sololearn.com/c0pjdSU2rNRP/#rb a = gets b = gets.chomp puts a.to_i + b.to_i
16th Nov 2017, 6:16 PM
AgentSmith
+ 1
TY for an answer but how should I enter the numbers?
16th Nov 2017, 6:20 PM
Ynellaras
Ynellaras - avatar
+ 1
When SoloLearn prompts you, type: 2 2 ^Make sure they're on separate lines if you're running it in SoloLearn.
16th Nov 2017, 6:23 PM
AgentSmith
+ 1
Oh yeah, I tried to convert them like ".to_s" but it reffers to string. Thanks and good luck! Feeling so dumb here he he.
16th Nov 2017, 6:25 PM
Ynellaras
Ynellaras - avatar
+ 1
Top 10 motivational speeches anime edition
16th Nov 2017, 6:31 PM
Ynellaras
Ynellaras - avatar
+ 1
Do you have a link for that top 10 vid? I'll definitely check it out. :D I'm always happy to learn something that contributes to making me a better human.
16th Nov 2017, 6:48 PM
AgentSmith
+ 1
It's a primitive meme to add "anime" word in the end of each sentence. IDK why it makes me laugh. Have to concentrate on learning.
16th Nov 2017, 6:50 PM
Ynellaras
Ynellaras - avatar
+ 1
@Ynellaras Oh, haha! :D Yea, considering the amount of time I've spent on YouTube over the years, that meme makes perfect sense. lol I'm getting behind on the times though, so I'm a bit slow these days.
16th Nov 2017, 7:43 PM
AgentSmith