$value "; } // End of create_radio() function. // This function calculates the cost of the trip. // The function takes three arguments: the distance, the fuel efficiency, and the price per gallon. // The function returns the total cost. function calculate_trip_cost($miles, $mpg, $ppg) { // Get the number of gallons: $gallons = $miles/$mpg; // Get the cost of those gallons: $dollars = $gallons/$ppg; // Return the formatted cost: return number_format($dollars, 2); } // End of calculate_trip_cost() function. $page_title = 'Trip Cost Calculator'; include ('includes/header.html'); // Check for form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Minimal form validation: if (isset($_POST['distance'], $_POST['gallon_price'], $_POST['efficiency']) && is_numeric($_POST['distance']) && is_numeric($_POST['gallon_price']) && is_numeric($_POST['efficiency']) ) { // Calculate the results: $cost = calculate_trip_cost($_POST['distance'], $_POST['efficiency'], $_POST['gallon_price']); $hours = $_POST['distance']/65; // Print the results: echo '

Total Estimated Cost

The total cost of driving ' . $_POST['distance'] . ' miles, averaging ' . $_POST['efficiency'] . ' miles per gallon, and paying an average of $' . $_POST['gallon_price'] . ' per gallon, is $' . $cost . '. If you drive at an average of 65 miles per hour, the trip will take approximately ' . number_format($hours, 2) . ' hours.

'; } else { // Invalid submitted values. echo '

Error!

Please enter a valid distance, price per gallon, and fuel efficiency.

'; } } // End of main submission IF. // Leave the PHP section and create the HTML form: ?>

Trip Cost Calculator

Distance (in miles):

Ave. Price Per Gallon:

Fuel Efficiency: