Bird
0
0

You want to calculate the total cost after applying a 15% discount on a price stored in $price. Which PHP expression correctly calculates the discounted price?

hard📝 Application Q15 of 15
PHP - Operators
You want to calculate the total cost after applying a 15% discount on a price stored in $price. Which PHP expression correctly calculates the discounted price?
A<code>$discounted = $price - ($price * 0.15);</code>
B<code>$discounted = $price + ($price * 0.15);</code>
C<code>$discounted = $price * 0.15;</code>
D<code>$discounted = $price / 0.15;</code>
Step-by-Step Solution
Solution:
  1. Step 1: Calculate the discount amount and subtract discount from original price

    Multiply the price by 0.15 to get 15% of the price. Subtract the discount amount from the original price to get the discounted price.
  2. Final Answer:

    $discounted = $price - ($price * 0.15); -> Option A
  3. Quick Check:

    Discounted price = price - 15% price [OK]
Quick Trick: Subtract 15% of price for discount [OK]
Common Mistakes:
  • Adding discount instead of subtracting
  • Using only 15% value without subtracting
  • Dividing price by 0.15 incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes