fork download
  1. <?php
  2. function calculateTotalAmount($creditSum, $percent, $commission, $accountPayment, $monthlyPayment) {
  3. $creditSum += $accountPayment; //Adding account opening fee
  4. $totalAmount = 0;
  5. while ($creditSum > 0) {
  6. $creditSum = $creditSum * $percent + $commission;
  7. if ($creditSum >= $monthlyPayment) {
  8. $creditSum -= $monthlyPayment;
  9. $totalAmount += $monthlyPayment;
  10. } else {
  11. $totalAmount += $creditSum;
  12. $creditSum -= $creditSum;
  13. }
  14. }
  15. return $totalAmount;
  16. }
  17.  
  18. $creditSum = 39999;
  19. $monthlyPayment = 5000;
  20.  
  21. $homoCredit = calculateTotalAmount($creditSum, 1.04, 500, 0, $monthlyPayment);
  22. $softBank = calculateTotalAmount($creditSum, 1.03, 1000, 0, $monthlyPayment);
  23. $strawberryBank = calculateTotalAmount($creditSum, 1.02, 0, 7000, $monthlyPayment);
  24.  
  25. echo "homoCredit: $homoCredit \n";
  26. echo "SoftBank: $softBank \n";
  27. echo "StrawberryBank: $strawberryBank ";
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
homoCredit: 56423.563121625 
SoftBank: 61268.718210807 
StrawberryBank: 52593.772021577