The drop1.amount or drop2.amount of Drop object in this example will not increase after the first time theyre run through.
class Drop
attr_accessor :item, :price, :amount
end
drop1 = Drop.new()
drop1.item = "item1"
drop1.price = 2247
drop1.amount = 1
drop2 = Drop.new()
drop2.item = "item2"
drop2.price = 4401
drop2.amount = 60
x = 0
array = []
while x < 10
rand1 = rand(2)
if rand1 == 0
if array.include? drop1.item
drop1.amount = drop1.amount + 1
else
array << drop1.item
array << drop1.amount
end
elsif rand1 == 1
if array.include? drop2.item
drop2.amount = drop2.amount + 60
else
array << drop2.item
array << drop2.amount
end
end
x += 1
end
puts array.to_s.gsub('"', '').gsub('[', '').gsub(']', '')
puts ""
puts drop1.amount
puts drop2.amount
Example of expected output:
item2, 240, item1, 6
6
240
Example of actual result:
item2, 60, item1, 1
6
240
I am looking for a change to the else statements in lines 24 and 32. The purpose of the this program is to create an array of items that will display the "item" one time and an incremented "amount" when a drop is randomly chosen multiple times.