How do I assign a monetary value to each array within Ruby?

  Kiến thức lập trình

I’m creating a Ruby program that ask how many computers you want and its has arrays for computers, monitors, and a free item. I want to add a cost to each of the arrays. If I could add a value to each item within the array that would be great but may be too complicated for me to understand as a beginner.

what I have thus far:

`def computer_order()
puts “how many computers with monitors would you like today?”
number = gets.chomp
number = number.to_i
number
end

def monitor_and_computer()
computer_type = [“Dell Inspiron”, “HP Pro”, “Acer Vero”, “Lenovo Ideacentre”, “Dell Optiplex”, “HP Envy”]
monitor_type = [“Dell 27′ Curved”, “Viewsonic 22′ Flat”, “LG 24′ Flat”, “Samsung 27′ Curved”, “Spectre 27′ Flat”, “MSI 31.5′ Curved”]
free_item = [“250G Thumb drive”, “Declan’s Shop T-Shirt”, “25$ Steam Gift Card”]
cost = 600

number_of_computers = computer_order()
number_of_computers = number_of_computers.to_i
total = (number_of_computers * cost)
total = total.to_s

number_of_computers.times do 
    puts "One computer is  " +  computer_type.sample + ", " + monitor_type.sample + ", " + free_item.sample
end 
   puts "Your total is: $" + total

end

monitor_and_computer()`

New contributor

D Rey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT