I have the following statement:
A parking charge a minimum fee of $ 2.00 to park by three hours. An additional $ 0.50 per hour does not necessarily whole is charged after the first three hours. The maximum value for any given period of 24 hours is $ 10.00. Suppose no car stationed for more than 24 hours at a time. Write an application calculate and display the parking fees for each customer who I parked in this garage yesterday. You must enter the hours of parking for each client. The program should display the charge for the current customer and calculate and display the total received at the end of the day. The program must use a load-valued function to determine the charge for each customer.
This is what I tried to do:
<?php
if ($_POST) {
$t = $_POST['num-hor'];
$total = valorApagar($t);
echo"<br><br>Total: R$".number_format($total, 2, ',', '.');
}
function valorApagar($t){
$total = 0;
if ($t <= 3) {
$total = 2;
}else if ($t > 3 && $t < 24) {
$total = 2;
$t -= 3;
if(is_int($t) == true){
$total += $t;
}else{
$t = ceil($t);
$t *= 0.5;
$total += $t;
}
}else {
$total = 10;
}
return $total;
}
?>
The function valorApagar()
is not returning the correct result, how do I adjust it to return the result as it is requested in the statement?