fork(2) download
  1. <?php
  2.  
  3.  
  4. function getCreditTotal($creditSum, $percent, $comission, $payout, $paymentTotal) {
  5. for ($month = 1; $month < 20; $month ++) {
  6.  
  7. $creditSum = ( $creditSum * $percent ) + $comission - $payout;
  8. $paymentTotal = $paymentTotal + $payout;
  9.  
  10. if ($creditSum < 0) {
  11. break;
  12. } elseif ($creditSum < 4000) {
  13. $creditSum = ( $creditSum * $percent ) + $comission;
  14. $paymentTotal = $paymentTotal + $creditSum;
  15. $creditSum = $creditSum - $creditSum;
  16. echo "{$month} месяц спустя: долг = {$creditSum} руб, выплачено всего {$paymentTotal} руб. \n";
  17. break;
  18. }
  19. }
  20.  
  21. return $paymentTotal;
  22. }
  23. $creditSum = 40000;
  24. $payout = 5000;
  25. $homoCreditTotal = getCreditTotal($creditSum, 1.04, 500, $payout, 0);
  26. $softBankTotal = getCreditTotal($creditSum, 1.03, 1000, $payout, 0);
  27. $strawberryBankTotal = getCreditTotal($creditSum, 1.02, 0, $payout, 0) + 7777;
  28. echo "homoCredit:{$homoCreditTotal}\nsoftBank:{$softBankTotal}\nstrawberryBank:{$strawberryBankTotal}";
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
11 месяц спустя: долг = 0 руб, выплачено всего 56425.164153843 руб. 
12 месяц спустя: долг = 0 руб, выплачено всего 61270.186744521 руб. 
8 месяц спустя: долг = 0 руб, выплачено всего 44030.560589315 руб. 
homoCredit:56425.164153843
softBank:61270.186744521
strawberryBank:51807.560589315