fork(2) download
  1. <?php
  2.  
  3.  
  4. function getCostPhone($cost, $monthlyPayment, $percent, $commission = 0, $openPayment = 0)
  5. {
  6. $credit = $cost + $openPayment;
  7. $totalPayment = 0;
  8.  
  9. for ($month = 1; $credit > 0; $month++) {
  10. $credit = $credit * $percent + $commission;
  11. if ($credit > $monthlyPayment) {
  12. $totalPayment += $monthlyPayment;
  13. $credit -= $monthlyPayment;
  14. } else {
  15. $totalPayment += $credit;
  16. $credit = 0;
  17. }
  18. }
  19.  
  20. return $totalPayment;
  21. }
  22.  
  23. $homoCredit = getCostPhone(39999, 5000, 1.04, 500);
  24. $softBank = getCostPhone(39999, 5000, 1.03, 1000);
  25. $strawberryBank = getCostPhone(39999, 5000, 1.02, 0, 7777);
  26.  
  27. echo "homoCredit: {$homoCredit} руб.\n";
  28. echo "softBank: {$softBank} руб.\n";
  29. echo "strawberryBank: {$strawberryBank} руб.\n";
Success #stdin #stdout 0.02s 24920KB
stdin
Standard input is empty
stdout
homoCredit: 56423.563121625 руб.
softBank: 61268.718210807 руб.
strawberryBank: 53559.8738592 руб.