use warnings; use strict; use constant { PII => 3.1416, DIVISOR => 61.02374409, # cubic inches to litres divisor RADIUS => 2.5, DEPTH => 6, }; my $cubic_inches = (RADIUS * RADIUS) * PII * DEPTH; # total cubes my $litres = $cubic_inches / DIVISOR; # total litres my $empty_depth_inches = 2.80; # inches from top of tank to current liquid level printf("total cubic inches: %f\n", $cubic_inches); printf("total litres: %f\n", $litres); printf("current empty litres: %f\n", empty_litres($empty_depth_inches)); printf("current litres: %f\n", current_litres($empty_depth_inches)); printf( "percent litres remaining: %f\n", current_litres($empty_depth_inches) / $litres * 100 ); printf( "percent litres missing: %f\n", empty_litres($empty_depth_inches) / $litres * 100 ); printf( "percent cubes remaining: %f\n", current_cubic_inches($empty_depth_inches) / $cubic_inches * 100 ); sub current_cubic_inches { my ($empty_inches) = @_; return (RADIUS * RADIUS) * PII * (DEPTH - $empty_inches); } sub empty_litres { my ($empty_inches) = @_; return $litres - (current_cubic_inches($empty_inches) / DIVISOR); } sub current_litres { my ($empty_inches) = @_; return $litres - empty_litres($empty_inches); } #### total cubic inches: 117.810000 total litres: 1.930560 current empty litres: 0.900928 current litres: 1.029632 percent litres remaining: 53.333333 percent litres missing: 46.666667 percent cubes remaining: 53.333333