Recap - Simple Math
Part of the Fundamentals section of Coddy's Ruby journey — lesson 14 of 88.
Challenge
EasyYou are provided with the following variables:
price = 45
quantity = 8
discount = 10
tax_rate = 5Calculate and display the following values in order, each on a separate line:
- The subtotal (price multiplied by quantity)
- The discount amount (subtotal multiplied by discount, then divided by
100.0) - The price after discount (subtotal minus discount amount)
- The tax amount (price after discount multiplied by tax_rate, then divided by
100.0) - 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 putsAll lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 42Variables and Data Types
Numbers and VariablesString Data TypeBoolean Data TypeSymbol Data TypeChecking Data TypesNaming ConventionsRecap - Variable Creation8Loops
For Loop with RangesWhile LoopBreakNextRecap - FactorialTimes LoopUntil LoopNested LoopsRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators6Basic IO
Output with putsOutput with print and pOutput With VariablesInput with getsChomp MethodType ConversionRecap - Age CalculatorRecap - True or False