In: Computer Science
Given the following:
- One bus can carry 20 passengers.
- One car can carry 2 passengers.
Provide an application using PHP that calculates the number of buses and cars needed based on a number of passengers entered. You need to also calculate how many passengers will be left after all the full vehicles are determined.
PHP file :
<!DOCTYPE html>
<html lang="en">
<head>
<!-- title for web page -->
<title>passengers</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<!-- html form -->
<form action="passengers.php" method="post">
Enter number of passengers :
<!-- textbox for passengers -->
<input type="text" name="numberOfPassengers"/>
<br><br>
<!-- butoon to submit form -->
<input type="submit" name="btnSubmit"/>
</form>
<?php
if(isset($_POST['btnSubmit']))
{
//taking number of passengers entered by user
$numberOfPassengers=$_POST['numberOfPassengers'];
//display passengers
echo "<h3>Number of Passengers : ".$numberOfPassengers."</h3></br>";
//checking buses required
echo "<p>Number of buses required : ".floor($numberOfPassengers/20)."</p>";
echo "<p>Number of passengers left : ".($numberOfPassengers%20)."</p>";
//checking cars required
echo "<p>Number of cars required : ".floor($numberOfPassengers/2)."</p>";
echo "<p>Number of passengers left : ".($numberOfPassengers%2)."</p>";
}
?>
</body>
</html>
==================================
Output :