Code Logo

Calculate Bakery Change

Published at19 Apr 2026
Calculations & Math Easy 3 views
Like0

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.

Learn about our pseudocode specification
Guide

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

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.

program calculate_bakery_change
dictionary
   total, paid, change: integer
algorithm
   input(total, paid)
   change <- paid - total
   output(change)
endprogram

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

Pseudocode - Approach 1
program calculate_bakery_change
dictionary
   total, paid, change: integer
algorithm
   input(total, paid)
   change <- paid - total
   output(change)
endprogram