<?php

error_reporting(-1);

$loan = 40000;// initial debt;
$percent = 1.03;// bank rate; 
$monthPay = 5000;// monthly amount of money paid
$totalAmount = 0;// total amount of money paid
$comission = 1000;// bank comission
$month = 0;// initial month

for (;$loan > 0;){ //while debt > 0
	
    $loan = $loan * $percent + $comission;// a bank is having its profit
    $month++;//loan continues

if ($loan > $monthPay) { // if loan greater than monthly paiment
	
	$loan -= $monthPay;// our schoolboy decreases  his debt by 5000 per month
	$totalAmount += $monthPay;// total amount increases by 5000
	}

elseif ($loan < $monthPay) { // else, if debt is less than 5000
	
	$totalAmount += $loan;// total amount increases by remainder
	$loan -= $loan;// the debt becomes 0
	}
	echo "$month month: loan is $loan, total amont is $totalAmount\n";
	//shows our schoolboy's total financial struggling

}
?>