<?php
function calculatePayments($credit, $percent, $service, $monthly, $paymentTotal) {
for ($month = 1; $month <= 20; $month ++) {
$compulsoryPayment = ( $credit * $percent ) + $service;
if ($compulsoryPayment > $monthly) {
$credit = $compulsoryPayment - $monthly;
$paymentTotal = $paymentTotal + $monthly;
}
elseif ($compulsoryPayment < $monthly) {
$credit = $credit - $credit;
$paymentTotal = $paymentTotal + $compulsoryPayment;
break;
}
}
return $paymentTotal;
}
$alfaBankTotal = calculatePayments(39999, 1.04, 500, 5000, 0);
$privatBankTotal = calculatePayments(39999, 1.03, 1000, 5000, 0);
$homeCreditTotal = calculatePayments(39999, 1.02, 0, 5000, 0) + 7777;
echo "AlfaBank = $alfaBankTotal\n";
echo "PrivatBank = $privatBankTotal\n";
echo "HomeCreditBank = $homeCreditTotal\n";
?>
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgpmdW5jdGlvbiBjYWxjdWxhdGVQYXltZW50cygkY3JlZGl0LCAkcGVyY2VudCwgJHNlcnZpY2UsICRtb250aGx5LCAkcGF5bWVudFRvdGFsKSB7CgoJZm9yICgkbW9udGggPSAxOyAkbW9udGggPD0gMjA7ICRtb250aCArKykgewogCgkkY29tcHVsc29yeVBheW1lbnQgPSAoICRjcmVkaXQgKiAkcGVyY2VudCApICsgJHNlcnZpY2U7CiAKCQlpZiAoJGNvbXB1bHNvcnlQYXltZW50ID4gJG1vbnRobHkpIHsKCQkJJGNyZWRpdCA9ICRjb21wdWxzb3J5UGF5bWVudCAtICRtb250aGx5OwoJCQkkcGF5bWVudFRvdGFsID0gJHBheW1lbnRUb3RhbCArICRtb250aGx5OwoJCX0KIAoJCWVsc2VpZiAoJGNvbXB1bHNvcnlQYXltZW50IDwgJG1vbnRobHkpIHsKCQkgICAJJGNyZWRpdCA9ICRjcmVkaXQgLSAkY3JlZGl0OwoJCSAgIAkkcGF5bWVudFRvdGFsID0gJHBheW1lbnRUb3RhbCArICRjb21wdWxzb3J5UGF5bWVudDsKCQkgICAJYnJlYWs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