fork download
  1. <?php
  2.  
  3.  
  4. $monthly = 5000;
  5. $credit = 39999;
  6. $penalty = 7777;
  7.  
  8. function calculatePayments($credit, $monthly, $percent, $service, $paymentTotal) {
  9.  
  10. for ($month = 1; $credit != 0; $month ++) {
  11.  
  12. $compulsory = ( $credit * $percent ) + $service;
  13. $payment = min($compulsory, $monthly);
  14. $credit = $compulsory - $payment;
  15. $paymentTotal = $paymentTotal + $payment;
  16. }
  17.  
  18. return $paymentTotal;
  19. }
  20.  
  21. $alfaBankTotal = calculatePayments($credit, $monthly, 1.04, 500, 0);
  22. $privatBankTotal = calculatePayments($credit, $monthly, 1.03, 1000, 0);
  23. $homeCreditTotal = calculatePayments($credit + $penalty, $monthly, 1.02, 0, 0);
  24.  
  25. echo "AlfaBank = $alfaBankTotal\n";
  26. echo "PrivatBank = $privatBankTotal\n";
  27. echo "HomeCreditBank = $homeCreditTotal\n";
  28.  
  29. ?>
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
AlfaBank = 56423.563121625
PrivatBank = 61268.718210807
HomeCreditBank = 53559.8738592