<?php
$creditBalance = 1000;
$percent = 1.03;
$serviceFee = 1000;
$monthlyPayment = 5000;
$paymentTotal = 0;
for ($months = 1; $months <= 20; $months ++) {
$creditBalance = ($creditBalance * $percent) + $serviceFee - $monthlyPayment;
$paymentTotal = $paymentTotal + $monthlyPayment;
echo "At the end of the month #{$months}: debt = {$creditBalance}, total payment by now = {$paymentTotal} \n";
if (($creditBalance * $percent) + $serviceFee < 5000) {
$paymentTotal = $paymentTotal + ($creditBalance * $percent) + $serviceFee;
$months++;
break;
}
}
echo "Eventually in the month #{$months} the boy has totally paid {$paymentTotal}";
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgokY3JlZGl0QmFsYW5jZSA9IDEwMDA7CiRwZXJjZW50ID0gMS4wMzsKJHNlcnZpY2VGZWUgPSAxMDAwOwokbW9udGhseVBheW1lbnQgPSA1MDAwOwokcGF5bWVudFRvdGFsID0gMDsKCmZvciAoJG1vbnRocyA9IDE7ICRtb250aHMgPD0gMjA7ICRtb250aHMgKyspIHsKICAgICRjcmVkaXRCYWxhbmNlID0gKCRjcmVkaXRCYWxhbmNlICogJHBlcmNlbnQpICsgJHNlcnZpY2VGZWUgLSAkbW9udGhseVBheW1lbnQ7CiAgICAkcGF5bWVudFRvdGFsID0gJHBheW1lbnRUb3RhbCArICRtb250aGx5UGF5bWVudDsKICAgIGVjaG8gIkF0IHRoZSBlbmQgb2YgdGhlIG1vbnRoICN7JG1vbnRoc306IGRlYnQgPSB7JGNyZWRpdEJhbGFuY2V9LCB0b3RhbCBwYXltZW50IGJ5IG5vdyA9IHskcGF5bWVudFRvdGFsfSBcbiI7CgogICAgaWYgKCgkY3JlZGl0QmFsYW5jZSAqICRwZXJjZW50KSArICRzZXJ2aWNlRmVlIDwgNTAwMCkgewogICAgCiAgICAkcGF5bWVudFRvdGFsID0gJHBheW1lbnRUb3RhbCArICgkY3JlZGl0QmFsYW5jZSAqICRwZXJjZW50KSArICRzZXJ2aWNlRmVlOwogICAgJG1vbnRocysrOwogICAgYnJlYWs7Cn0KfQoKZWNobyAiRXZlbnR1YWxseSBpbiB0aGUgbW9udGggI3skbW9udGhzfSB0aGUgYm95IGhhcyB0b3RhbGx5IHBhaWQgeyRwYXltZW50VG90YWx9IjsK