<?php
function calc( $creditBalance , $monthlyPayment , $percent , $servicePayment , $paymentTotal ) {
for ( $month = 1 ; $month <= 20 ; $month ++ ) { /*Общий цикл с подсчётом расходов*/
$debt = ( $creditBalance * $percent ) + $servicePayment ; /*Долг, который отличается от изначальной суммы (КредитБаланс)*/
if ( $debt <= $monthlyPayment ) { /*Если долг меньше суммы месячной выплаты или равен ей*/
$creditBalance = 0 ;
$paymentTotal = $paymentTotal + $debt ;
echo "{$month} месяц(-ев) до {$creditBalance} руб. Должно быть выплачено всего {$paymentTotal} руб.\n " ;
break ;
} else { /*Если долг остаётся больше суммы месячной выплаты*/
$creditBalance = ( $creditBalance * $percent ) + $servicePayment - $monthlyPayment ;
$paymentTotal = $paymentTotal + $monthlyPayment ;
}
}
}
$creditBalance = 40000 ;
$monthlyPayment = 5000 ;
$homoCreditTotal = calc( $creditBalance , $monthlyPayment , 1.04 , 500 , 0 ) ;
$softBankTotal = calc( $creditBalance , $monthlyPayment , 1.03 , 1000 , 0 ) ;
$strawberryBankTotal = calc( $creditBalance + 7777 , $monthlyPayment , 1.02 , 1000 , 0 ) ;
echo "{$homoCreditTotal} \n " ;
echo "{$softBankTotal} \n " ;
echo "{$strawberryBankTotal} \n " ;
?>
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgpmdW5jdGlvbiBjYWxjKCRjcmVkaXRCYWxhbmNlLCAkbW9udGhseVBheW1lbnQsICRwZXJjZW50LCAkc2VydmljZVBheW1lbnQsICRwYXltZW50VG90YWwpIHsKCWZvciAoJG1vbnRoID0gMTsgJG1vbnRoIDw9IDIwOyAkbW9udGggKyspIHsgLyrQntCx0YnQuNC5INGG0LjQutC7INGBINC/0L7QtNGB0YfRkdGC0L7QvCDRgNCw0YHRhdC+0LTQvtCyKi8KIAoJJGRlYnQgPSAoJGNyZWRpdEJhbGFuY2UgKiAkcGVyY2VudCkgKyAkc2VydmljZVBheW1lbnQ7IC8q0JTQvtC70LMsINC60L7RgtC+0YDRi9C5INC+0YLQu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