<?php
function calculateTotalAmount($creditSum, $percent, $commission, $accountPayment, $monthlyPayment) {
$creditSum += $accountPayment; //Adding account opening fee
$totalAmount = 0;
while ($creditSum > 0) {
$creditSum = $creditSum * $percent + $commission;
if ($creditSum >= $monthlyPayment) {
$creditSum -= $monthlyPayment;
$totalAmount += $monthlyPayment;
} else {
$totalAmount += $creditSum;
$creditSum -= $creditSum;
}
}
return $totalAmount;
}
$creditSum = 39999;
$monthlyPayment = 5000;
$homoCredit = calculateTotalAmount($creditSum, 1.04, 500, 0, $monthlyPayment);
$softBank = calculateTotalAmount($creditSum, 1.03, 1000, 0, $monthlyPayment);
$strawberryBank = calculateTotalAmount($creditSum, 1.02, 0, 7000, $monthlyPayment);
echo "homoCredit: $homoCredit \n";
echo "SoftBank: $softBank \n";
echo "StrawberryBank: $strawberryBank ";
PD9waHAKZnVuY3Rpb24gY2FsY3VsYXRlVG90YWxBbW91bnQoJGNyZWRpdFN1bSwgJHBlcmNlbnQsICRjb21taXNzaW9uLCAkYWNjb3VudFBheW1lbnQsICRtb250aGx5UGF5bWVudCkgewogICAgJGNyZWRpdFN1bSArPSAkYWNjb3VudFBheW1lbnQ7IC8vQWRkaW5nIGFjY291bnQgb3BlbmluZyBmZWUKICAgICR0b3RhbEFtb3VudCA9IDA7CiAgICB3aGlsZSAoJGNyZWRpdFN1bSA+IDApIHsKICAgICAgICAkY3JlZGl0U3VtID0gJGNyZWRpdFN1bSAqICRwZXJjZW50ICsgJGNvbW1pc3Npb247CiAgICAgICAgaWYgKCRjcmVkaXRTdW0gPj0gJG1vbnRobHlQYXltZW50KSB7CiAgICAgICAgICAgICRjcmVkaXRTdW0gLT0gJG1vbnRobHlQYXltZW50OwogICAgICAgICAgICAkdG90YWxBbW91bnQgKz0gJG1vbnRobHlQYXltZW50OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICR0b3RhbEFtb3VudCArPSAkY3JlZGl0U3VtOwogICAgICAgICAgICAkY3JlZGl0U3VtIC09ICRjcmV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