Code Logo

Calculate Bakery Change

Published at19 Apr 2026
Easy 0 views
Like0

This problem comes from a very normal bakery checkout moment. A customer buys something, hands over some money, and now you need to figure out how much change to give back.

You are given the total cost of the order and the amount paid by the customer. The answer is the difference between those two values.

For example, if the total is 18 and the customer pays 25, the answer is 7. That means the cashier should return 7 in change.

So the task is simply to subtract the order total from the paid amount and print the result.

Example Input & Output

Example 1
Input
total = 42, paid = 50
Output
8
Explanation

The cashier should return 8.

Example 2
Input
total = 18, paid = 25
Output
7
Explanation

The customer pays 25 for an order that costs 18, so the change is 7.

Example 3
Input
total = 10, paid = 10
Output
0
Explanation

If the paid amount matches the total, there is no change.

Algorithm Flow

Recommendation Algorithm Flow for Calculate Bakery Change
Recommendation Algorithm Flow for Calculate Bakery Change

Solution Approach

A simple way to solve this is to use one subtraction.

First, read the two numbers: the total price and the amount paid. After that, calculate how much is left after covering the order cost.

The formula is:

change <- paid - total

That line gives you the exact amount the customer should get back.

Once you have that value, print it as the answer.

This problem stays very direct because it only needs one arithmetic step.

Best Answers

Solutions Coming Soon

Verified best solutions for this Challenge are still being analyzed and will be available soon.