I'm trying to do a program that asks the user for three numbers one at a time, store them in array, then print the list of the numbers and the total.
Please explain.
Here is what I have so far:
numbers = Array.new
numbers = []
puts "Enter first number: "
first = gets.to_i
puts "Enter second number: "
second = gets.to_i
puts "Enter third number: "
third = gets.to_i
def sum(numbers)
return 0 if numbers.length < 1
result = 0
numbers.each { |num| result += num }
result
end
numbersarrays, which are identical?#summethod is available only via ActiveSupport. It isn't present in Plain Ol' Ruby.