fork(1) download
  1. <?php
  2.  
  3.  
  4. function credit($percent, $service, $oneTimePay) { //Процентная ставка, ежемесячный платёж, единоразовый платёж
  5. $creditBalance = 39999; //сумма кредита
  6. $paymentTotal = 0; //общая сумма выплат
  7. $mountlyPayment = 5000; //ежемесячная выплата
  8.  
  9. $creditBalance = $creditBalance + $oneTimePay;
  10.  
  11. for ($mounth = 0; $creditBalance > 0; $mounth++) {
  12. $creditBalance = ($creditBalance * $percent) + $service;
  13.  
  14. if ($creditBalance < $mountlyPayment) { //проверка не больше ли месячный платёж остатка по кредиту, чтобы банк не залез в минус
  15. $mountlyPayment = $creditBalance;
  16. }
  17.  
  18. $creditBalance = $creditBalance - $mountlyPayment;
  19. $paymentTotal = $paymentTotal + $mountlyPayment;
  20. }
  21.  
  22. return $paymentTotal; //возврат общей суммы выплат
  23. }
  24.  
  25. $homoCreditBank = credit(1.04, 500, 0);
  26. $softBank = credit(1.03, 1000, 0);
  27. $strawberryBank = credit(1.02, 0, 7777);
  28. echo "HomoCreditBank: {$homoCreditBank}\n";
  29. echo "SoftBank: {$softBank}\n";
  30. echo "StrawberryBank: {$strawberryBank}\n";
  31. ?>
  32.  
  33.  
  34.  
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
HomoCreditBank: 56423.563121625
SoftBank: 61268.718210807
StrawberryBank: 53559.8738592