Skip to content

Commit

Permalink
chapter draft changes
Browse files Browse the repository at this point in the history
  • Loading branch information
LarryUllman committed May 7, 2017
1 parent 4546ac4 commit 5ff4c82
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
20 changes: 10 additions & 10 deletions ch03/calculator.php
Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -49,29 +49,29 @@ function calculate_trip_cost($miles, $mpg, $ppg) {
$hours = $_POST['distance']/65;

// Print the results:
echo '<h1>Total Estimated Cost</h1>
<p>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.</p>';
echo '<div class="page-header"><h1>Total Estimated Cost</h1></div>
<p>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.</p>';

} else { // Invalid submitted values.
echo '<h1>Error!</h1>
<p class="error">Please enter a valid distance, price per gallon, and fuel efficiency.</p>';
echo '<div class="page-header"><h1>Error!</h1></div>
<p class="text-danger">Please enter a valid distance, price per gallon, and fuel efficiency.</p>';
}

} // End of main submission IF.

// Leave the PHP section and create the HTML form:
?>

<h1>Trip Cost Calculator</h1>
<div class="page-header"><h1>Trip Cost Calculator</h1></div>
<form action="calculator.php" method="post">
<p>Distance (in miles): <input type="text" name="distance" value="<?php if (isset($_POST['distance'])) echo $_POST['distance']; ?>"></p>
<p>Ave. Price Per Gallon: <span class="input">
<p>Distance (in miles): <input type="number" name="distance" value="<?php if (isset($_POST['distance'])) echo $_POST['distance']; ?>"></p>
<p>Ave. Price Per Gallon:
<?php
create_radio('3.00');
create_radio('3.50');
create_radio('4.00');
?>
</span></p>
</p>
<p>Fuel Efficiency: <select name="efficiency">
<option value="10"<?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '10')) echo ' selected="selected"'; ?>>Terrible</option>
<option value="20"<?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '20')) echo ' selected="selected"'; ?>>Decent</option>
Expand Down
19 changes: 9 additions & 10 deletions ch03/script_03_08/calculator.php
Expand Up @@ -34,31 +34,30 @@ function create_gallon_radio($value) {
$hours = $_POST['distance']/65;

// Print the results:
echo '<h1>Total Estimated Cost</h1>
<p>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.</p>';
echo '<div class="page-header"><h1>Total Estimated Cost</h1></div>
<p>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.</p>';

} else { // Invalid submitted values.
echo '<h1>Error!</h1>
<p class="error">Please enter a valid distance, price per gallon, and fuel efficiency.</p>';
echo '<div class="page-header"><h1>Error!</h1></div>
<p class="text-danger">Please enter a valid distance, price per gallon, and fuel efficiency.</p>';
}

} // End of main submission IF.

// Leave the PHP section and create the HTML form:
?>

<h1>Trip Cost Calculator</h1>
<div class="page-header"><h1>Trip Cost Calculator</h1></div>
<form action="calculator.php" method="post">
<p>Distance (in miles): <input type="text" name="distance" value="<?php if (isset($_POST['distance'])) echo $_POST['distance']; ?>"></p>
<p>Ave. Price Per Gallon: <span class="input">
<p>Distance (in miles): <input type="number" name="distance" value="<?php if (isset($_POST['distance'])) echo $_POST['distance']; ?>"></p>
<p>Ave. Price Per Gallon:
<?php
create_gallon_radio('3.00');
create_gallon_radio('3.50');
create_gallon_radio('4.00');
?>
</span></p>
<p>Fuel Efficiency:
<select name="efficiency">
</p>
<p>Fuel Efficiency: <select name="efficiency">
<option value="10"<?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '10')) echo ' selected="selected"'; ?>>Terrible</option>
<option value="20"<?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '20')) echo ' selected="selected"'; ?>>Decent</option>
<option value="30"<?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '30')) echo ' selected="selected"'; ?>>Very Good</option>
Expand Down
18 changes: 9 additions & 9 deletions ch03/script_03_09/calculator.php
Expand Up @@ -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');
Expand All @@ -34,29 +34,29 @@ function create_radio($value, $name = 'gallon_price') {
$hours = $_POST['distance']/65;

// Print the results:
echo '<h1>Total Estimated Cost</h1>
<p>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.</p>';
echo '<div class="page-header"><h1>Total Estimated Cost</h1></div>
<p>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.</p>';

} else { // Invalid submitted values.
echo '<h1>Error!</h1>
<p class="error">Please enter a valid distance, price per gallon, and fuel efficiency.</p>';
echo '<div class="page-header"><h1>Error!</h1></div>
<p class="text-danger">Please enter a valid distance, price per gallon, and fuel efficiency.</p>';
}

} // End of main submission IF.

// Leave the PHP section and create the HTML form:
?>

<h1>Trip Cost Calculator</h1>
<div class="page-header"><h1>Trip Cost Calculator</h1></div>
<form action="calculator.php" method="post">
<p>Distance (in miles): <input type="text" name="distance" value="<?php if (isset($_POST['distance'])) echo $_POST['distance']; ?>"></p>
<p>Ave. Price Per Gallon: <span class="input">
<p>Distance (in miles): <input type="number" name="distance" value="<?php if (isset($_POST['distance'])) echo $_POST['distance']; ?>"></p>
<p>Ave. Price Per Gallon:
<?php
create_radio('3.00');
create_radio('3.50');
create_radio('4.00');
?>
</span></p>
</p>
<p>Fuel Efficiency: <select name="efficiency">
<option value="10"<?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '10')) echo ' selected="selected"'; ?>>Terrible</option>
<option value="20"<?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '20')) echo ' selected="selected"'; ?>>Decent</option>
Expand Down

0 comments on commit 5ff4c82

Please sign in to comment.