For a recent project, I programmed a simple tip calculator using HTML and Java Script. Here is a sample code:
<html>
<head>
<title>Tip Calculator by MyProgrammingTips.com</title>
</head>
<body>
<script type=”text/javascript”>
document.write(”<h1>Tip Calculator by MyProgrammingTips.com</h1>”);
//Variables
var subtotal, percent, total;
//Input
subtotal=parseFloat(prompt(”Enter your bill amount before tips”,”100.00″));
percent=parseFloat(prompt(”Enter your desired tip percentage”,”20%”));
//Processing
tip=subtotal*(percent/100);
tip=Math.round(tip*100)/100;
total=subtotal+tip;
total=Math.round(total*100)/100;
//Output
document.write(”<p>Your bill amount before tips is $” + subtotal + “.”);
document.write(”<p>Your tip percentage is ” + percent +”%” + “.”);
document.write(”<p>Your tip is $” + tip.toFixed(2) + “.”);
document.write(”<p>Your total amount is $” + total.toFixed(2) + “.”);
</script>
</body>
</html>
<!–
Adrian Chu
Section 03
January 24, 2008
–>
<html>
<head>
<title>Tip Calculator by Adrian Chu</title>
</head>
<body>
<script type=”text/javascript”>
document.write(”<h1>Tip Calculator by Adrian Chu</h1>”);
//Variables
var subtotal, percent, total;
//Input
subtotal=parseFloat(prompt(”Enter your bill amount before tips”,”100.00″));
percent=parseFloat(prompt(”Enter your desired tip percentage”,”20%”));
//Processing
tip=subtotal*(percent/100);
tip=Math.round(tip*100)/100;
total=subtotal+tip;
total=Math.round(total*100)/100;
//Output
document.write(”<p>Your bill amount before tips is $” + subtotal + “.”);
document.write(”<p>Your tip percentage is ” + percent +”%” + “.”);
document.write(”<p>Your tip is $” + tip.toFixed(2) + “.”);
document.write(”<p>Your total amount is $” + total.toFixed(2) + “.”);
</script>
</body>
</html>
Check it out and let me know what you think. It currently relies on prompts to ask you how much your subtotal is and how much of a percentage you would like to give as gratuity/tips. A challenge for you can be to make it into a form-based program. Good luck!