fork download
  1. <?php
  2.  
  3. function creditCount($creditBalance, $monthlyPayment, $percent, $servicePayment, $additionalPayment = 0){
  4. if ($additionalPayment>0) {
  5. $creditBalance += $additionalPayment;
  6. }
  7. $paymentTotal = 0; /* Сколько всего отдал банку анон */
  8.  
  9. /* Посчитаем расходы 20 раз на 20 месяцев вперед */
  10. for ($month = 1; $month <= 20; $month++) {
  11. $creditBalance = ( $creditBalance * $percent ) + $servicePayment;
  12. $payment = min($creditBalance, 5000);
  13. $creditBalance -= $payment;
  14. $paymentTotal += $payment;
  15.  
  16. /* Если баланс отрицательный — хватит считать */
  17. if ($creditBalance <= 0) {
  18. break;
  19. }
  20. }
  21.  
  22. return $paymentTotal;
  23.  
  24. };
  25.  
  26. $homecredit = creditCount(40000, 5000, 1.04, 500);
  27. $softbank = creditCount(40000, 5000, 1.03, 1000);
  28. $strawberry = creditCount(40000, 5000, 1.02, 0, 7777);
  29.  
  30. echo 'homecredit: ' . $homecredit . "\n";
  31. echo 'softbank: ' . $softbank . "\n";
  32. echo 'strawberry: ' . $strawberry . "\n";
  33.  
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
homecredit: 56425.164153843
softbank: 61270.186744521
strawberry: 53561.117233508