<?php
function countTotalCost ( $percent , $serviceFee ) {
for ( $months = 2 , $debt = 39999 , $monthlyPayment = 5000 , $paymentTotal = 0 ; $months < 32 ; $months ++ ) {
$debt = $debt + ( $debt * $percent ) + $serviceFee - 5000 ;
$paymentTotal = $paymentTotal + $monthlyPayment ;
if ( $serviceFee == 7777 ) {
$debt = $debt - $serviceFee ;
}
if ( $debt + ( $debt * $percent ) + $serviceFee < $monthlyPayment ) {
$paymentTotal = $paymentTotal + $debt + ( $debt * $percent ) + $serviceFee ;
$months ++;
break ;
}
}
return $paymentTotal ;
}
$creditSum = 39999 ;
$payOut = 5000 ;
$homoCreditTotal = countTotalCost ( 1.04 , 500 ) ;
$softBankTotal = countTotalCost ( 1.03 , 1000 ) ;
$strawberryBankTotal = countTotalCost ( 1.02 , 7777 ) ;
echo "If you go to HomoCredit you'll pay {$homoCreditTotal} rubles eventually \n " ;
echo "If you go to SoftBank you'll pay {$softBankTotal} rubles eventually \n " ;
echo "If you go to StawberryBank you'll pay {$strawberryBankTotal} rubles eventually \n " ;
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgpmdW5jdGlvbiBjb3VudFRvdGFsQ29zdCAoJHBlcmNlbnQsICRzZXJ2aWNlRmVlKSB7CiAgICBmb3IgKCRtb250aHMgPSAyLCAkZGVidCA9IDM5OTk5LCAkbW9udGhseVBheW1lbnQgPSA1MDAwLCAkcGF5bWVudFRvdGFsID0gMDsgJG1vbnRocyA8IDMyOyAkbW9udGhzKyspIHsKICAgICAgICAkZGVidCA9ICRkZWJ0ICsgKCRkZWJ0ICogJHBlcmNlbnQpICsgJHNlcnZpY2VGZWUgLSA1MDAwOwogICAgICAgICRwYXltZW50VG90YWwgPSAkcGF5bWVudFRvdGFsICsgJG1vbnRobHlQYXltZW50OwogICAgaWYgKCRzZXJ2aWNlRmVlID09IDc3NzcpIHsKICAgICAgICAkZGVidCA9ICRkZWJ0IC0gJHNlcnZpY2VGZWU7Cn0KICAgIGlmICgkZGVidCArICgkZG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