PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Getting input
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Getting input

Réponse
 
LinkBack Outils de la discussion
Vieux 03/12/2007, 21h49   #1
Erik Boling
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Getting input

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-forum.com/.

  Réponse avec citation
Vieux 03/12/2007, 22h16   #2
Justin Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting input

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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 06h05.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09882 seconds with 10 queries