# Getting input

**URL:** <https://www.ruby-forum.com/t/getting-input/122025>\
**Category:** Ruby\
**Created:** [December 3, 2007, 10:49pm UTC](https://www.ruby-forum.com/t/getting-input/122025 "2007-12-03T22:49:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dust](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@dust](https://www.ruby-forum.com/u/dust)\
**Post date:** [December 3, 2007, 10:49pm UTC](https://www.ruby-forum.com/t/getting-input/122025/1 "2007-12-03T22:49:32Z")

</div>

I have been trying to get find a way to get input from the user, and be  
able to store in a variable using shoes GUI, but i can’t quite figure it  
out? Does any one know how to? I know you can _replace_ but that not  
working for what im trying to do… if ur wondering, heres the program  
that im trying to put a GUI on…  
@correct = 0  
@total = 0  
def pose\_multiplication\_problem  
@total = @total + 1  
multiple2 = rand(11)  
multiple1 = rand(11)  
answer = multiple1 \* multiple2  
puts “What is #{multiple1} \* #{multiple2} ?”  
answerp = gets.chomp.to\_i  
if answer == answerp  
puts “Good job”  
@correct = @correct + 1  
else  
puts 'Sorry, you fail, correct answer is ’ + answer.to\_s  
end  
end  
puts ‘How many problems do you want to solve?’  
this\_many = gets.chomp.to\_i  
oldtime = Time.now  
this\_many.times do  
pose\_multiplication\_problem  
end  
puts @correct.to\_s + ‘/’ + @total.to\_s + ‘correct’

---

<div class="post-metadata">

**Author:** ![dust](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c2a13f/32.png) [@dust](https://www.ruby-forum.com/u/dust)\
**Post date:** [December 3, 2007, 11:17pm UTC](https://www.ruby-forum.com/t/getting-input/122025/2 "2007-12-03T23:17:03Z")

</div>

Erik B. wrote:

> ```
> multiple1 = rand(11)
> 
> ```
> 
> puts ‘How many problems do you want to solve?’  
> this\_many = gets.chomp.to\_i  
> oldtime = Time.now  
> this\_many.times do  
> pose\_multiplication\_problem  
> end  
> puts @correct.to\_s + ‘/’ + @total.to\_s + ‘correct’

This should get you started:

Shoes.app do  
multiple2 = rand(11)  
multiple1 = rand(11)  
answer = multiple1 \* multiple2  
questionbox = stack { para “What is #{multiple1} \* #{multiple2}  
?” }

```
    answerp = edit_line

    button("Submit Answer") do
            if answerp.text.to_i == answer
                    alert "Correct!"
            else
                    alert "Sorry, answer is actually #{answer}"
            end
            multiple2 = rand(11)
            multiple1 = rand(11)
            answer = multiple1 * multiple2
            questionbox.clear { para "What is #{multiple1} *

```

#{multiple2} ?" }  
end  
end

-Justin
