TAX_RATE = 5.5 def calculate_tax_for(item_price) item_price * (TAX_RATE / 100) end puts("How many items are you purchasing?") total_items = gets.chomp.to_i item_quantities = [] item_prices = [] total_items.times do |i| puts("Enter price for item #{i + 1}:") item_prices << gets.chomp.to_f puts("Enter quantity for item #{i + 1}: ") item_quantities << gets.chomp.to_i end subtotal = 0 tax = 0 item_prices.each do |price| item_quantities.each do |qty| subtotal += price * qty # subtotal = subtotal + price * qty tax += calculate_tax_for(subtotal) # tax = tax + (price * qty) * (TAX_RATE / 100) end end puts("Subtotal: #{subtotal.round(2)}€") puts("Tax: #{tax.round(2)}€") puts("Total: #{(subtotal + tax).round(2)}€")