0
0
MATLABdata~30 mins

Arithmetic operators in MATLAB - Mini Project: Build & Apply

Choose your learning style9 modes available
Arithmetic Operators in MATLAB
📖 Scenario: You are helping a small shop owner calculate the total cost of items bought by customers. You will use arithmetic operators to add, subtract, multiply, and divide prices and quantities.
🎯 Goal: Build a simple MATLAB script that uses arithmetic operators to calculate the total price, discount, and final amount to pay.
📋 What You'll Learn
Create variables with exact names and values for prices and quantities
Use arithmetic operators: addition (+), subtraction (-), multiplication (*), and division (/)
Calculate total cost before discount
Calculate discount amount using a discount rate
Calculate final amount after discount
Print the final amount
💡 Why This Matters
🌍 Real World
Calculating prices and discounts is common in shops and online stores to help customers know how much to pay.
💼 Career
Understanding arithmetic operations and variables is essential for programming tasks in data analysis, finance, and software development.
Progress0 / 4 steps
1
Create item prices and quantities
Create variables called priceApple with value 3, priceBanana with value 2, qtyApple with value 5, and qtyBanana with value 7.
MATLAB
Need a hint?

Use the assignment operator = to set values to variables.

2
Set discount rate
Create a variable called discountRate and set it to 0.1 (which means 10%).
MATLAB
Need a hint?

Discount rate is a decimal number representing percentage.

3
Calculate total cost and discount
Calculate the total cost before discount in a variable called totalCost by multiplying prices and quantities and adding them. Then calculate the discount amount in a variable called discountAmount by multiplying totalCost by discountRate.
MATLAB
Need a hint?

Use * for multiplication and + for addition.

4
Calculate final amount and display
Calculate the final amount to pay in a variable called finalAmount by subtracting discountAmount from totalCost. Then print the finalAmount using disp.
MATLAB
Need a hint?

Use - for subtraction and disp to show the result.