diff --git a/ch03/calculator.php b/ch03/calculator.php index 4bad4d1..dc9631f 100644 --- a/ch03/calculator.php +++ b/ch03/calculator.php @@ -16,7 +16,7 @@ function create_radio($value, $name = 'gallon_price') { // Complete the element: echo "> $value "; -} // End of create_radio() function. +} // End of create_gallon_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. @@ -27,7 +27,7 @@ function calculate_trip_cost($miles, $mpg, $ppg) { $gallons = $miles/$mpg; // Get the cost of those gallons: - $dollars = $gallons/$ppg; + $dollars = $gallons * $ppg; // Return the formatted cost: return number_format($dollars, 2); @@ -49,12 +49,12 @@ function calculate_trip_cost($miles, $mpg, $ppg) { $hours = $_POST['distance']/65; // Print the results: - echo '
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.
'; + echo '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 'Please enter a valid distance, price per gallon, and fuel efficiency.
'; + echo 'Please enter a valid distance, price per gallon, and fuel efficiency.
'; } } // End of main submission IF. @@ -62,16 +62,16 @@ function calculate_trip_cost($miles, $mpg, $ppg) { // Leave the PHP section and create the HTML form: ?> -