# How to pass user input data to variables to solve formula

**URL:** <https://www.ruby-forum.com/t/how-to-pass-user-input-data-to-variables-to-solve-formula/159874>\
**Category:** Ruby-Forum\
**Created:** [February 9, 2009, 4:35pm UTC](https://www.ruby-forum.com/t/how-to-pass-user-input-data-to-variables-to-solve-formula/159874 "2009-02-09T16:35:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lecandotnet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f9ae1b/32.png) [@lecandotnet](https://www.ruby-forum.com/u/lecandotnet)\
**Post date:** [February 9, 2009, 4:35pm UTC](https://www.ruby-forum.com/t/how-to-pass-user-input-data-to-variables-to-solve-formula/159874/1 "2009-02-09T16:35:36Z")

</div>

I known that to compute series of number, we have to

puts #{(2+19)/3}  
we have answer = 7

How to enter inputs from keyboard to do math, for variables as number 2  
above, such as

puts #{(var +19)/3}

I tried puts var, printf #{var}, var=STDIN, STDOUT.puts var, all without  
error but no answer!

It is working OK, if I have a given var with a value number:  
var=2  
puts #{(var +19)/3}  
I will have answer = 7

Otherwise, if we put:

STDOUT.puts var  
puts #{(var +19)/3}

error is: undefined local variable or method

Thank You

---

<div class="post-metadata">

**Author:** ![lecandotnet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f9ae1b/32.png) [@lecandotnet](https://www.ruby-forum.com/u/lecandotnet)\
**Post date:** [March 12, 2009, 6:09am UTC](https://www.ruby-forum.com/t/how-to-pass-user-input-data-to-variables-to-solve-formula/159874/2 "2009-03-12T06:09:28Z")

</div>

Can Le wrote:

> I known that to compute series of number, we have to
> 
> puts #{(2+19)/3}  
> we have answer = 7
> 
> How to enter inputs from keyboard to do math, for variables as number 2  
> above, such as
> 
> puts #{(var +19)/3}
> 
> I tried puts var, printf #{var}, var=STDIN, STDOUT.puts var, all without  
> error but no answer!
> 
> It is working OK, if I have a given var with a value number:  
> var=2  
> puts #{(var +19)/3}  
> I will have answer = 7
> 
> Otherwise, if we put:
> 
> STDOUT.puts var  
> puts #{(var +19)/3}
> 
> error is: undefined local variable or method
> 
> Thank You

print “Enter a value?”  
var = gets  
puts (var.to\_i+19)/3

try this, i hope it helps you.

Thank you
