Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- values = []
- number = 0
- result = 0
- # Builds the array. Ends when user press enter on an empty line.
- while not number.to_s.empty?
- number = gets.chomp
- values << number.to_i
- end
- # Pops the last slot, the 'nil'.
- values.pop
- # The sum of the values.
- values.each do |value|
- result = result + value
- end
- puts result
Add Comment
Please, Sign In to add comment