Advertisement
Nurrohman_rex

calculateTaxiFare

Apr 1st, 2024
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. <?php
  2. function calculateTaxiFare($seconds, $mileage, $type) {
  3. $baseFare = 2;
  4. $timeRate = 0.02;
  5. $mileageRate = 1.2;
  6. $nightMultiplier = 2;
  7.  
  8. $fare = $baseFare + ($timeRate * $seconds) + ($mileageRate * $mileage);
  9.  
  10.  
  11. if ($type === "night") {
  12. $fare *= $nightMultiplier;
  13. }
  14.  
  15. return number_format($fare, 2) . " $";
  16. }
  17.  
  18.  
  19. echo calculateTaxiFare(120, 2.2, "day") . "\n";
  20. echo calculateTaxiFare(120, 2.2, "night") . "\n";
  21. echo calculateTaxiFare(300, 4.1, "day") . "\n";
  22. echo calculateTaxiFare(300, 4.1, "night") . "\n";
  23. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement