<?php
$creditBalance = 1000;
$percent = 1.03;
$servicePayment = 1000;
$monthlyPayment = 5000;
$paymentTotal = 0;
for ($month = 1; $month <= 20; $month ++) {
$creditBalance = ( $creditBalance * $percent ) + $servicePayment; /* - $monthlyPayment */
$paymentTotal = $paymentTotal + $monthlyPayment;
$obligation = $creditBalance - $paymentTotal;
echo "{$month} месяц спустя:\n сумма долга = {$creditBalance} руб;\n выплачено всего - {$paymentTotal} руб.; \n обязательство $obligation\n \n";
if ($obligation <= $monthlyPayment) {
$lastPay = $monthlyPayment - ($monthlyPayment - $obligation);
$paymentTotal = $paymentTotal + $lastPay;
/* $obligation = $obligation - $lastpay; */
$obligation = $creditBalance - $paymentTotal;
echo "последний платёж - $lastPay, ";
$obligation = $creditBalance - $paymentTotal;
echo "обязательство $obligation";
break;
}
}
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgokY3JlZGl0QmFsYW5jZSA9IDEwMDA7CiRwZXJjZW50ID0gMS4wMzsKJHNlcnZpY2VQYXltZW50ID0gMTAwMDsKJG1vbnRobHlQYXltZW50ID0gNTAwMDsKJHBheW1lbnRUb3RhbCA9IDA7Cgpmb3IgKCRtb250aCA9IDE7ICRtb250aCA8PSAyMDsgJG1vbnRoICsrKSB7CgkKCSRjcmVkaXRCYWxhbmNlID0gKCAkY3JlZGl0QmFsYW5jZSAqICRwZXJjZW50ICkgKyAkc2VydmljZVBheW1lbnQ7IAkJLyogIC0gJG1vbnRobHlQYXltZW50ICovCgkkcGF5bWVudFRvdGFsID0gJHBheW1lbnRUb3RhbCArICRtb250aGx5UGF5bWVudDsKCSRvYmxpZ2F0aW9uID0gJGNyZWRpdEJhbGFuY2UgLSAkcGF5bWVudFRvdGFsOwoJZWNobyAieyRtb250aH0g0LzQtdGB0Y/RhiDRgdC/0YPRgdGC0Y86XG4g0YHRg9C80LzQsCDQtNC+0LvQs9CwID0geyRjcmVkaXRCYWxhbmNlfSDRgNGD0LE7XG4g0LLRi9C/0LvQsNGH0LXQvd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