No. Total Price (RM) Discount

1. Less than 100 10%
2. Greater than 100 but less than 200 15%
3. Greater than 200 but less than 300 20%
4. Greater than 300 25%

analyse the calculation of total prices and discount based on customer’s purchases at the sundry shop. Customers may buy many products in multiple quantities and you will need to consider the prices of each item and its quantity.

Based on the above programming problem:
i. Analyse the problem to identify required items to be used in designing algorithm
ii. Write an algorithm in a pseudo code
iii. Draw a flowchart based on the pseudo code
iv. Produce a Tracing Table that will show the projected values for a customer’s purchases total price and discount.

i. Required items:

- Customer's purchases
- Prices of each item
- Quantity of each item

ii. Pseudocode:
1. Initialize variables:
- total_price = 0
- discount_percent = 0

2. Prompt the user for the number of items they purchased:
- num_items

3. For each item:
a. Prompt the user for the price of the item:
- price_item
b. Prompt the user for the quantity of the item:
- quantity_item
c. Calculate the price for the item:
- item_total = price_item * quantity_item
d. Add the item_total to the total_price

4. Determine the discount percentage based on the total price:
- If total_price is less than 100, set discount_percent to 10
- If total_price is greater than 100 but less than 200, set discount_percent to 15
- If total_price is greater than 200 but less than 300, set discount_percent to 20
- If total_price is greater than 300, set discount_percent to 25

5. Calculate the discount_amount:
- discount_amount = (total_price * discount_percent) / 100

6. Calculate the final_price:
- final_price = total_price - discount_amount

7. Output the total_price, discount_percent, discount_amount, and final_price

iii. Flowchart:

Start
|

┌─────┴─────┐
│ │
Get num_items │
│ │
↓ │
┌─────────────┐ │
│ │ │
For each item │ │
│ │ │
↓ │ │
┌──────┴───┐ │ │
│ │ │ │
Get price_item Get quantity_item
│ │ │ │
↓ ↓ │ │
│ ┌──────┴─────┐ │ │
│ │ │ │ │
│ Calculate │ │ │
│ item_total │ │ │
│ │ │ │
↓ ↓ ↓ ↓
│ │ │ ╷
│ Add item_total ╷
↓ ↓ │ │
│ │ │ │
└───────┐ │ │ │
│ │ │ │
└───>│ │ │
│ │ │
↓ ↓ │
│ Determine │ │
│ discount_percent │
│ │ │
│ ↓ │
│ Conditionals to │
│ determine the │
│ discount_percent │
│ │ │
│ ↓ │
│ Calculate │ │
│ discount_amount │ │
│ │ │
↓ ↓ │
│ │ │
└───────┐ │ │
│ │ │
↓ ↓ ↓
│ Calculate │
│ final_price │
│ │
↓ ↓
│ │
Output results

End

iv. Tracing Table:

| Item | Price | Quantity | Item Total |
|--------|-------|----------|------------|
| Item1 | 10 | 3 | 30 |
| Item2 | 20 | 2 | 40 |
| Item3 | 15 | 1 | 15 |
|--------|-------|----------|------------|
| Total | | | 85 |

| Total Price | Discount Percent | Discount Amount | Final Price |
|-------------|-----------------|-----------------|-------------|
| 85 | 10 | 8.5 | 76.5 |