fork(1) download
  1. <?php
  2.  
  3.  
  4. $creditBalance = 40000;
  5. $percent = 1.03;
  6. $serviceFee = 1000;
  7. $monthlyPayment = 5000;
  8. $paymentTotal = 0;
  9.  
  10. for ($months = 1; $months <= 20; $months ++) {
  11. $creditBalance = ($creditBalance * $percent) + $serviceFee - $monthlyPayment;
  12. $paymentTotal = $paymentTotal + $monthlyPayment;
  13. echo "At the end of the month #{$months}: debt = {$creditBalance}, total payment by now = {$paymentTotal} \n";
  14.  
  15. if (($creditBalance * $percent) + $serviceFee < 5000) {
  16.  
  17. $paymentTotal = $paymentTotal + ($creditBalance * $percent) + $serviceFee;
  18. $months++;
  19. break;
  20. }
  21. }
  22.  
  23. echo "Eventually in the month #{$months} the boy has totally paid {$paymentTotal}";
  24.  
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
At the end of the month #1: debt = 37200, total payment by now = 5000 
At the end of the month #2: debt = 34316, total payment by now = 10000 
At the end of the month #3: debt = 31345.48, total payment by now = 15000 
At the end of the month #4: debt = 28285.8444, total payment by now = 20000 
At the end of the month #5: debt = 25134.419732, total payment by now = 25000 
At the end of the month #6: debt = 21888.45232396, total payment by now = 30000 
At the end of the month #7: debt = 18545.105893679, total payment by now = 35000 
At the end of the month #8: debt = 15101.459070489, total payment by now = 40000 
At the end of the month #9: debt = 11554.502842604, total payment by now = 45000 
At the end of the month #10: debt = 7901.137927882, total payment by now = 50000 
At the end of the month #11: debt = 4138.1720657184, total payment by now = 55000 
At the end of the month #12: debt = 262.31722768997, total payment by now = 60000 
Eventually in the month #13 the boy has totally paid 61270.186744521