fork download
<?php
 
function calculateCredit($percent, $commission, $years, $creditSum, $payout, $downPayment){
	$creditSum += $downPayment;
	$totalPaid = 0;
	for($i=0; $i<$years; $i++){
		$creditSum = ($creditSum * $percent + $commission);
		if($creditSum > $payout){
			$creditSum -= $payout;
			$totalPaid += $payout; 
		}
		else{$totalPaid += $creditSum; $creditSum -= $creditSum; break;}
	}
	return $totalPaid;
}
 
$homoCreditTotal = calculateCredit(1.04, 500, 15, 39999, 5000, 0);
$softbankTotal = calculateCredit(1.03, 1000, 15, 39999, 5000, 0);
$strawberryBankTotal = calculateCredit(1.02, 0, 15, 39999, 5000, 7777);
 
echo "homoCredit: {$homoCreditTotal} руб.\n";
echo "softbank: {$softbankTotal} руб. \n";
echo "strawberryBank: {$strawberryBankTotal} руб. \n";
Success #stdin #stdout 0.02s 24508KB
stdin
Standard input is empty
stdout
homoCredit: 56423.563121625 руб.
softbank: 61268.718210807 руб. 
strawberryBank: 53559.8738592 руб.