This one is comparatively easy. It wants the user to do a self-checkout with items at a store, where it prompts for a quantity of items and their individual price, and then it figures out the subtotal, applies the tax, and then the total, and prints out each. Now that I’m looking at it again, it really is very simple:
require ‘../useful_methods.rb’
item_1_price = getInteger(“Enter the price of item 1:”)
quantity_1 = getInteger(“Enter the quantity of item 1:”)
item_2_price = getInteger(“Enter the price of item 2:”)
quantity_2 = getInteger(“Enter the quantity of item 2:”)
item_3_price = getInteger(“Enter the price of item 3:”)
quantity_3 = getInteger(“Enter the quantity of item 3:”)
tax_rate = 0.055
subtotal = item_1_price * quantity_1 + item_2_price * quantity_2 + item_3_price * quantity_3
tax = subtotal * tax_rate
total = subtotal + tax
puts “Subtotal: $#{subtotal.to_f.round(2)}”
puts “Tax: $#{tax}”
puts “Total: $#{total}”
This one feels like a lot more busy work than the previous challenges, but it does have the interesting aspect that it asks you to make sure the numerical values are in money form; you wouldn’t want $5.50 to be shortened to $5.5.
Anyway, that’s day 10 of 57!