[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Getting input

Erik Boling

12/3/2007 9:49:00 PM

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'
--
Posted via http://www.ruby-....

1 Answer

Justin Collins

12/3/2007 10:16:00 PM

0

Erik Boling wrote:
> 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