<?php
include('includes/header.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tip Calculator</title>
</head>
<body>
<h1>Ashlynn's Tip Calculator</h1>
<form method="POST">
<label for="totalBill">Enter the total bill amount:</label><br>
<input type="number" id="totalBill" name="totalBill" step="0.01" required><br><br>
<input type="submit" value="Calculate Tips">
</form>
<?php
function calculateTip($totalBill, $tipPercentage) {
return $totalBill * ($tipPercentage / 100);
}
function displayResults($totalBill, $tip15, $tip20, $totalWithTip15, $totalWithTip20) {
return "
<h2>Results</h2>
<p>Original Bill: $$totalBill</p>
<p>15% Tip: $$tip15 (Total with Tip: $$totalWithTip15)</p>
<p>20% Tip: $$tip20 (Total with Tip: $$totalWithTip20)</p>";
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// input total bill
$totalBill = $_POST['totalBill'];
// calculate tips for 15% and 20%
$tip15 = calculateTip($totalBill, 15);
$tip20 = calculateTip($totalBill, 20);
// calculate totals including tip
$totalWithTip15 = $totalBill + $tip15;
$totalWithTip20 = $totalBill + $tip20;
echo displayResults(number_format($totalBill, 2), number_format($tip15, 2), number_format($tip20, 2),
number_format($totalWithTip15, 2), number_format($totalWithTip20, 2));
}
?>
<?php
include('includes/footer.php');
?>
</body>
</html>