Getting input

E

Erik Boling

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'
 
J

Justin Collins

Erik said:
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'
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top