puts "Quel âge tu as ?"
print ">"
age = gets.chomp.to_i
i = 0
while age > 0
puts "Il y a " + age.to_s + " ans" + " tu avais : " + i.to_s + " ans"
age -= 1
i += 1
break if age = i
puts "Il y a " + age.to_s + " ans" + " tu avais la moitié de ton âge !"
age = i
end
I have a problem with my program on Ruby On Rails. I apologize in advance for my English.
I train on this language by doing an exercise that allows you to enter your age, and to see how old you are in a given year.
But for example. When we reach half our age, for example 20 years old I want to display (in french)
"Ten years ago, you were half your age!"
that I wanted to put thanks to the "break if", but that produces only one line of code. I hope you have understood otherwise do not hesitate to ask for clarification.
Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire