<?php
homoCredit(40000);
function homoCredit($cost) {
	$balance=0;
	$total=0;
	for ($i=1; $balance > 0; $i++) {
		$balance=$cost*1.04+500;
		if ($balance >= 5000) {
			$balance -= 5000;
			$total += $i*5000;
		}
		else {
			$total += $balance;
			$balance = 0;
		}
	}
	echo "$total";
	return $total;
}

/*$cost=39999;
$homoCreditTotal = homoCredit($cost);
echo "homocredit - $homoCreditTotal"; */