Calculate Bakery Change
Imagine you are running a cozy neighborhood bakery. The smell of fresh bread is in the air, and a customer has just picked out a delicious selection of pastries. They hand you some cash, and now it is up to you to quickly and accurately calculate their change so they can be on their way with a smile.
You have two pieces of information: the total cost of their treats and the amount of money they handed over. Your job is to find the difference. Whether it is a few coins or several bills, the math is the same—it is all about making sure the transaction is fair and correct.
For example, if the pastries cost 15 and the customer hands you a 20, you know instantly that they should get 5 back. In this challenge, you will write a program that handles this subtraction for any order, ensuring your bakery checkout always runs smoothly.
Example Input & Output
The cashier should return 8.
The customer pays 25 for an order that costs 18, so the change is 7.
If the paid amount matches the total, there is no change.
Algorithm Flow

Solution Approach
To calculate the change, we just need to perform a single subtraction. We take the amount paid and subtract the total cost of the items. The result is the change we owe the customer.
This is a classic example of a simple subtraction logic. By storing the result in a variable like change, we keep our algorithm organized and easy to read. It handles every transaction in exactly one step, making it as efficient as it is practical for a real-world shop.
Best Answers
program calculate_bakery_change
dictionary
total, paid, change: integer
algorithm
input(total, paid)
change <- paid - total
output(change)
endprogramComments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
