<?php
function calculateLoan($loan, $percent, $monthlyPayment, $taxRate = 0)
{
$month = 0;
$totalPayment = 0;
while ($loan > 0) {
$totalPayment += $monthlyPayment;
$loan += $loan * $percent;
if ($loan + $taxRate > $monthlyPayment) {
$loan -= ($monthlyPayment - $taxRate);
} else {
$left = $monthlyPayment - ($loan + $taxRate);
$loan = 0;
}
$month++;
}
'total' => round($totalPayment - $left, 2), 'month' => $month,
'left' => round($left, 2), );
}
$loan = 40000;
$monthlyPayment = 5000;
$taxRate = $monthlyPayment * 0.03;
$percent = 0.03;
$data = calculateLoan($loan, $percent, $monthlyPayment, $taxRate);
echo "Выплачено: " . $data['total'] . " рублей.\n" . "За " . $data['month'] . " месяцев.\n" . "В конце месяца на булочки осталось: " . $data['left'] . " рублей.\n";
PD9waHAgCgplcnJvcl9yZXBvcnRpbmcoLTEpOwoKZnVuY3Rpb24gY2FsY3VsYXRlTG9hbigkbG9hbiwgJHBlcmNlbnQsICRtb250aGx5UGF5bWVudCwgJHRheFJhdGUgPSAwKQp7CiAgICAkbW9udGggPSAwOwogICAgJHRvdGFsUGF5bWVudCA9IDA7CgogICAgd2hpbGUgKCRsb2FuID4gMCkgewogICAgICAgICR0b3RhbFBheW1lbnQgKz0gJG1vbnRobHlQYXltZW50OwogICAgICAgICRsb2FuICs9ICRsb2FuICogJHBlcmNlbnQ7CgogICAgICAgIGlmICgkbG9hbiArICR0YXhSYXRlID4gJG1vbnRobHlQYXltZW50KSB7CiAgICAgICAgICAgICRsb2FuIC09ICgkbW9udGhseVBheW1lbnQgLSAkdGF4UmF0ZSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgJGxlZnQgPSAkbW9udGhseVBheW1lbnQgLSAoJGxvYW4gKyAkdGF4UmF0ZSk7CiAgICAgICAgICAgICRsb2FuID0gMDsKICAgICAgICB9CgogICAgICAgICRtb250aCsrOwogICAgfQoKICAgIHJldHVybiBhcnJheSgKICAgICAgICAndG90YWwnID0+IHJvdW5kKCR0b3RhbFBheW1lbnQgLSAkbGVmdCwgMiksCiAgICAgICAgJ21vbnRoJyA9PiAkbW9udGgsCiAgICAgICAgJ2xlZnQnICA9PiByb3VuZCgkbGVmdCwgMiksCiAgICApOwp9CgokbG9hbiAgICAgICAgICAgPSA0MDAwMDsKJG1vbnRobHlQYXltZW50ID0gNTAwMDsKJHRheFJhdGUgICAgICAgID0gJG1vbnRobHlQYXltZW50ICogMC4wMzsKJHBlcmNlbnQgICAgICAgID0gMC4wMzsKCiRkYXRhID0gY2FsY3VsYXRlTG9hbigkbG9hbiwgJHBlcmNlbnQsICRtb250aGx5UGF5bWVudCwgJHRheFJhdGUpOwoKZWNobyAi0JLRi9C/0LvQsNGH0LXQvdC+OiAiIC4gJGRhdGFbJ3RvdGFsJ10gLiAiINGA0YPQsdC70LXQuS5cbiIgLiAi0JfQsCAiIC4gJGRhdGFbJ21vbnRoJ10gLiAiINC80LXRgdGP0YbQtdCyLlxuIiAuICLQkiDQutC+0L3RhtC1INC80LXRgdGP0YbQsCDQvdCwINCx0YPQu9C+0YfQutC4INC+0YHRgtCw0LvQvtGB0Yw6ICIgLiAkZGF0YVsnbGVmdCddIC4gIiDRgNGD0LHQu9C10LkuXG4iOw==