Skip to content
Advertisement

I need to figure out how much paint is needed to cover an area, I’m having problems with it. Help me or give me an idea

$width = 10; //width
$length = 10; //Length
$door = 2; // Door area
$square = $width * $length - $door; //Total area to be painted
$perMeter = 1;  //Where $w is the amount of paint to paint 1m2
$total = $square * $perMeter; //The total amount of paint is sufficient for painting.
$containers = array(5,12,18,4,8,1); //The values for the number of containers are in liters.

How many barrels will be needed 5,12,18,4,8,1 (will gradually get from the largest part to the smallest part)

Advertisement

Answer

The whole file can look like that

<?php

declare(strict_types=1);

$width = 10; //width
$length = 10; //Length
$door = 2; // Door area
$square = $width * $length - $door; //Total area to be painted
$perMeter = 1;  //Where $w is the amount of paint to paint 1m2
$total = $square * $perMeter; //The total amount of paint is sufficient for painting.

echo 'Total barrels needed: ' . $total . "barrelsn";

$containers = array(5,12,18,4,8,1); //The values for the number of containers are in liters.

rsort($containers);

$counter = 0;

while ($counter < count($containers)) {
    $total -= ($amount = intdiv($total, $containers[$counter])) * $containers[$counter];
    echo sprintf("%d barrel container - %dn", $containers[$counter], $amount);
    $counter++;
}

Look at the variable names, meaningful variable names are very important, if you want your code to be supported easily. And of course you can change the value of variables.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement