<?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 ;
break ;
} else { /*Если долг остаётся больше суммы месячной выплаты*/
$creditBalance = ( $creditBalance * $percent ) + $servicePayment - $monthlyPayment ;
$paymentTotal = $paymentTotal + $monthlyPayment ;
}
}
return $paymentTotal ;
}
$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 "В банке HomoCredit Анончик выплатит всего {$homoCreditTotal} рублей\n " ;
echo "В банке SoftBank Анончик выплатит всего {$softBankTotal} рублей\n " ;
echo "В банке StrawberryBank Анончик выплатит всего {$strawberryBankTotal} рублей\n " ;
?>
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgpmdW5jdGlvbiBjYWxjKCRjcmVkaXRCYWxhbmNlLCAkbW9udGhseVBheW1lbnQsICRwZXJjZW50LCAkc2VydmljZVBheW1lbnQsICRwYXltZW50VG90YWwpIHsKCWZvciAoJG1vbnRoID0gMTsgJG1vbnRoIDw9IDIwOyAkbW9udGggKyspIHsgLyrQntCx0YnQuNC5INGG0LjQutC7INGBINC/0L7QtNGB0YfRkdGC0L7QvCDRgNCw0YHRhdC+0LTQvtCyKi8KIAoJJGRlYnQgPSAoJGNyZWRpdEJhbGFuY2UgKiAkcGVyY2VudCkgKyAkc2VydmljZVBheW1lbnQ7IC8q0JTQvtC70LMsINC60L7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