Menu
Coddy logo textTech

Recap - Simple Math

Part of the Fundamentals section of Coddy's Ruby journey — lesson 14 of 88.

challenge icon

Challenge

Easy

You are provided with the following variables:

price = 45
quantity = 8
discount = 10
tax_rate = 5

Calculate and display the following values in order, each on a separate line:

  1. The subtotal (price multiplied by quantity)
  2. The discount amount (subtotal multiplied by discount, then divided by 100.0)
  3. The price after discount (subtotal minus discount amount)
  4. The tax amount (price after discount multiplied by tax_rate, then divided by 100.0)
  5. The final total (price after discount plus tax amount)

Use variables to store each intermediate calculation before displaying it.

Try it yourself

# Given variables
price = 45
quantity = 8
discount = 10
tax_rate = 5

# TODO: Write your code below
# Calculate each value and store in variables:
# 1. subtotal
# 2. discount_amount
# 3. price_after_discount
# 4. tax_amount
# 5. final_total

# Then display each value on a separate line using puts

All lessons in Fundamentals