Check Liquid Balance Scale
This challenge is based on a real-world weighing scenario. A digital balance scale is used to compare the mass of liquid stored in two cylindrical containers: one on the left side and one on the right side.
Both containers have the same radius r, but they may contain different liquid heights and different liquid densities. You are given the radius of the container, the height of liquid on the left, the density of the left liquid, the height of liquid on the right, and the density of the right liquid.
To keep the arithmetic simple, use the simplified value pi = 3. The volume of a cylinder is:
The mass of the liquid is:
Your program must calculate the mass on both sides. If the two masses are equal, print BALANCE. Otherwise, print the absolute difference between the two masses.
This problem is designed to practice modular thinking. A clean solution separates the work into a function for volume, a function for mass, and a procedure to display the final scale result.
Example Input & Output
The left mass is 120 and the right mass is 144, so the scale difference is 24.
Both sides have mass 18, so the scale is balanced.
The left mass is 135 and the right mass is 108, so the difference is 27.
Algorithm Flow

Solution Approach
A good way to solve this problem is to break it into three smaller tasks.
First, create a function to compute the cylinder volume. Since the simplified rule in this problem is pi = 3, the formula becomes:
Second, create another function to compute the liquid mass. That function can call the volume function, then multiply the result by the density:
Third, create a procedure that compares the left mass and the right mass. If they are equal, output BALANCE. If they are different, output the absolute difference. Because there is no built-in absolute value requirement here, you can use a simple condition:
In the main program, read all inputs, compute the left and right masses with the helper functions, then call the display procedure. The overall running time is O(1) because the program only performs a fixed number of calculations and comparisons.
Best Answers
Solutions Coming Soon
Verified best solutions for this Challenge are still being analyzed and will be available soon.
Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
