Menu
Coddy logo textTech

Recap - Simple Calculations

Part of the Fundamentals section of Coddy's PHP journey — lesson 21 of 71.

challenge icon

Challenge

Easy

Read three numbers from input: basePrice, taxPercent, and quantity.

Calculate the final total by performing the following steps:

  1. Start with the base price
  2. Add the tax by multiplying the base price by (taxPercent / 100) and adding it to the price
  3. Multiply the result by the quantity
  4. Subtract a flat discount of 15 from the total
  5. Finally, add a shipping fee calculated as quantity ** 2

Print the final total.

Example:

If the inputs are 50, 10, and 2, the output should be 99 because:

  • Base price: 50
  • Add 10% tax: 50 + (50 * 10 / 100) = 50 + 5 = 55
  • Multiply by quantity 2: 55 * 2 = 110
  • Subtract discount 15: 110 - 15 = 95
  • Add shipping (2 ** 2 = 4): 95 + 4 = 99

Try it yourself

<?php
// Read input
$basePrice = intval(fgets(STDIN));
$taxPercent = intval(fgets(STDIN));
$quantity = intval(fgets(STDIN));

// TODO: Write your code below
// 1. Start with the base price
// 2. Add the tax (basePrice * taxPercent / 100)
// 3. Multiply by quantity
// 4. Subtract discount of 15
// 5. Add shipping fee (quantity ** 2)

// Output the final total
echo $finalTotal;
?>

All lessons in Fundamentals