# Torbert 9.7.2007 #def find_sum ex # total = 0 # ex.each { |term| total + term } # total #end def find_sum ex ex.inject(0) { |total, term| total + term } end print("Enter some arithmetic, addition of positive numbers only: "); expression = gets().chomp.split "+" puts "\n#{expression.inspect}" k=0 begin expression[k] = expression[k].strip.to_i k+=1 end while k!= expression.length puts expression.inspect() sum = find_sum(expression); puts "\nThe sum is #{sum}\n" puts "#{expression.map{|e| e.to_s}.join(" + ")} = #{sum}\n\n"