From: Gregory Brown Date: 2007-02-07T14:36:30+09:00 Subject: Re: newbie question On 2/7/07, Vincent Gabriel Franco wrote: > Thank you Jason, > That process had skipped my mind for some reason I thought just > setting the variable to true would kill the loop. > this is my revised code. > > My first program without just typing out an example from a book > > here we go. > > any suggestions on how to clean it up would be great. 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