<?php
function credit($commission, $percent, $creditSum, $payout){
for ($i=0; $creditSum > 0; $i++) {
$creditSum =($creditSum * $percent) + $commission;
if($creditSum< $payout){
$payout = $creditSum;
$creditSum = $creditSum - $payout;
break;
}elseif($creditSum >= $payout ){
$creditSum = $creditSum -$payout;
return;
}
}
}
$balance = credit(500,0.04,39999,5000);
echo "$balance";
PD9waHAKCmZ1bmN0aW9uIGNyZWRpdCgkY29tbWlzc2lvbiwgJHBlcmNlbnQsICRjcmVkaXRTdW0sICRwYXlvdXQpewoJZm9yICgkaT0wOyAkY3JlZGl0U3VtID4gMDsgJGkrKykgewoJJGNyZWRpdFN1bSA9KCRjcmVkaXRTdW0gKiAkcGVyY2VudCkgKyAkY29tbWlzc2lvbjsKCSAgaWYoJGNyZWRpdFN1bTwgJHBheW91dCl7CiAgCiAgCiAkcGF5b3V0ID0gJGNyZWRpdFN1bTsKCSAkY3JlZGl0U3VtID0gJGNyZWRpdFN1bSAtICRwYXlvdXQ7CgkgCQoJIAlicmVhazsKIAoJIH1lbHNlaWYoJGNyZWRpdFN1bSA+PSAkcGF5b3V0ICl7CiAKCSAJJGNyZWRpdFN1bSA9ICRjcmVkaXRTdW0gLSRwYXlvdXQ7CiAKCgkJCXJldHVybjsKIAoJCX0KCQkKCX0KCQoJCn0KCiRiYWxhbmNlID0gY3JlZGl0KDUwMCwwLjA0LDM5OTk5LDUwMDApOwoJZWNobyAiJGJhbGFuY2UiOwo=