0
0
PHPprogramming~15 mins

Arithmetic operators in PHP - Mini Project: Build & Apply

Choose your learning style9 modes available
Arithmetic Operators in PHP
📖 Scenario: You are helping a small shop owner calculate prices and discounts using simple math.
🎯 Goal: Build a PHP script that uses arithmetic operators to calculate total price, discount, and final price.
📋 What You'll Learn
Create variables with exact values
Use arithmetic operators: +, -, *, /
Print the final calculated result
💡 Why This Matters
🌍 Real World
Calculating prices, discounts, and totals is common in shopping and billing systems.
💼 Career
Understanding arithmetic operators is essential for backend programming, especially in e-commerce and finance applications.
Progress0 / 4 steps
1
Create initial price variables
Create two variables called $price1 and $price2 with values 100 and 50 respectively.
PHP
Need a hint?

Use the = operator to assign values to variables.

2
Add a discount percentage variable
Create a variable called $discountPercent and set it to 10.
PHP
Need a hint?

Remember to end each statement with a semicolon.

3
Calculate total price and discount amount
Create a variable $totalPrice that adds $price1 and $price2. Then create a variable $discountAmount that calculates $totalPrice times $discountPercent divided by 100.
PHP
Need a hint?

Use + to add and * and / for multiplication and division.

4
Calculate final price and print it
Create a variable $finalPrice that subtracts $discountAmount from $totalPrice. Then print the text "Final price: " followed by the value of $finalPrice.
PHP
Need a hint?

Use - to subtract and print() to show output.