Code Logo

Calculate Laundry Cost

Published at19 Apr 2026
Calculations & Math Easy 17 views
Like0

Imagine you're running a busy laundry shop in the middle of town. Customers are coming in with bags of clothes, and they want to know their total bill right away. Doing the math in your head for every customer is slow and can lead to mistakes.

To keep things moving, you want to build a simple calculator. The logic is straightforward: you weigh the laundry, check your set price per kilogram, and multiply them. If someone brings 5kg and you charge 7 per kg, they owe you 35. It's a fundamental business calculation that almost every service-based app needs to handle.

In this challenge, you'll formalize that logic. Your program should take the weight and the price as inputs, perform the calculation, and output the total so you can print out a perfect receipt every time.

Learn about our pseudocode specification
Guide

Example Input & Output

Example 1
Input
weight = 3, price_per_kg = 5
Output
15
Explanation

Multiply the weight by the price per kilogram.

Example 2
Input
weight = 6, price_per_kg = 4
Output
24
Explanation

6 kilograms at 4 per kilogram gives a total of 24.

Example 3
Input
weight = 0, price_per_kg = 7
Output
0
Explanation

No laundry weight means no cost.

Algorithm Flow

Recommendation Algorithm Flow for Calculate Laundry Cost
Recommendation Algorithm Flow for Calculate Laundry Cost

Solution Approach

Solving this challenge is all about mapping a real-world transaction into two clear steps: gathering information and performing a single calculation. In programming, we call this the Input-Process-Output (IPO) model.

First, we need to know the 'facts' of the transaction—the weight of the clothes and the price you charge per kilogram. Once we have those as inputs, we use a single multiplication to find the total. In pseudocode, we use an assignment arrow to store that result before printing it out.

program calculate_laundry_cost
dictionary
   weight, price_per_kg, total_cost: integer
algorithm
   input(weight, price_per_kg)
   total_cost <- weight * price_per_kg
   output(total_cost)
endprogram

Why use this structure? By defining our variables in the dictionary, we make it clear to anyone reading the code exactly what data we're handling. The calculation itself is incredibly efficient, running in O(1) time complexity, meaning it stays just as fast whether you're charging for 1kg or 1,000,000kg. It's the cleanest way to handle a predictable, linear business rule.

Best Answers

Pseudocode - Approach 1
program calculate_laundry_cost
dictionary
   weight, price_per_kg, total: integer
algorithm
   input(weight, price_per_kg)
   total <- weight * price_per_kg
   output(total)
endprogram