Gets.chomp into an Array

I have an assignment for class. I have to input each monthly bill for each month.
I begin with months = Array.new [“January”, “February”, …]
the user needs to input how much the bill was for each month
so then i put bill = gets.chomp

so it would be like
puts “Enter all the bills for each month”
bills = gets.chomp
user puts 123 234 345 456…
im stuck on getting each bill into an array
so it displays
123
234
345
456

I hope this makes sense :confused:

Have you tried << or push into array?

bills = Array.new
months.each do |m|
  print "#{m}: "
  input = gets.chomp.to_i
  bills.push(input)
end
bills = gets.chomp

or if you want integers

bills = gets.chomp.map(&:to_i)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs