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 '

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.

'; + 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 '

Error!

-

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: ?> -

Trip Cost Calculator

+
-

Distance (in miles):

-

Ave. Price Per Gallon: +

Distance (in miles):

+

Ave. Price Per Gallon: -

+

Fuel Efficiency:

-

Ave. Price Per Gallon: +

Distance (in miles):

+

Ave. Price Per Gallon: -

-

Fuel Efficiency: - diff --git a/ch03/script_03_09/calculator.php b/ch03/script_03_09/calculator.php index 571fbf9..8176f3d 100644 --- a/ch03/script_03_09/calculator.php +++ b/ch03/script_03_09/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. $page_title = 'Trip Cost Calculator'; include('includes/header.html'); @@ -34,12 +34,12 @@ function create_radio($value, $name = '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 $' . number_format ($dollars, 2) . '. 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 $' . number_format ($dollars, 2) . '. 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.

'; + echo ' +

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

'; } } // End of main submission IF. @@ -47,16 +47,16 @@ function create_radio($value, $name = 'gallon_price') { // Leave the PHP section and create the HTML form: ?> -

Trip Cost Calculator

+ -

Distance (in miles):

-

Ave. Price Per Gallon: +

Distance (in miles):

+

Ave. Price Per Gallon: -

+

Fuel Efficiency: