Guest User

Untitled

a guest
Jul 17th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. values = []
  2. number = 0
  3. result = 0
  4.  
  5. # Builds the array. Ends when user press enter on an empty line.
  6. while not number.to_s.empty?
  7. number = gets.chomp
  8. values << number.to_i
  9. end
  10.  
  11. # Pops the last slot, the 'nil'.
  12. values.pop
  13.  
  14. # The sum of the values.
  15. values.each do |value|
  16. result = result + value
  17. end
  18.  
  19. puts result
Add Comment
Please, Sign In to add comment