From: Vincent Gabriel Franco Date: 2007-02-08T23:45:27+09:00 Subject: Re: newbie question Thanks for the links Gregory! nice to have a warm welcome instead of a flame hello world of ruby Gregory Brown wrote: > > I had a little trouble understanding what your code is supposed to do, > but this code will keep asking you for numbers until you answer with > an empty response (just hit enter) > > It shows the equations as you enter them, and then in the end gives > you a summary of the one's you've entered. It does not account for > all possible errors. > > Look up String#empty, Array#<<, break, loop, and > Array#each_with_index to understand a bit better what's going on. > > Welcome to Ruby. You might try out http://tryruby.hobix.com as well > as get acquainted with the documentation at http://ruby-doc.org > > Glad to see you hacking, newbie or not :) > > firsts = [] > seconds = [] > answers = [] > loop do > puts 'Enter a number' > first = gets.chomp > break if first.empty? > firsts << first_number = first.to_i > puts '...good.' > puts 'Now enter a number to multiply to the first number' > second = gets.chomp > break if second.empty? > seconds << second_number = second.to_i > answers << answer = (first_number * second_number) > puts "#{first_number} * #{second_number} = #{answer}" > end > > puts 'okay now we are going to look at all the questions your asked' > answers.each_with_index do |c,i| > puts "#{firsts[i]} * #{seconds[i]} = #{c}" > end > >