A mail-order house sells five different products whose retail prices are as foll
ID: 3682900 • Letter: A
Question
A mail-order house sells five different products whose retail prices are as follows: product 1, $2.98; product 2, $4.50; product 3, $9.98; product 4, $4.49; and product 5, $6.87. Write an application that reads a series of pairs of numbers as follows: a) Product number b) Quantity sold for one day Your program must use a switch structure to help determine the retail price for each product. It should calculate and display the total retail value of each product sold last week. Use a sentinel-controlled loop to determine when the program should stop looping and display the final results.
I want it as an HTML scripts not for c++
Explanation / Answer
<html>
<head>
<title>Product </title>
<script>
function calPrice()
{
var p1=document.getElementById('p1').value;
var p2=document.getElementById('p2').value;
var p3=document.getElementById('p3').value;
var p4=document.getElementById('p4').value;
var p5=document.getElementById('p5').value;
var tprice=(p1*getPrice(1)) + (p2*getPrice(2)) + (p3*getPrice(3)) + (p4*getPrice(4)) + (p5*getPrice(5)) ;
document.getElementById("tprice").value=tprice;
return false;
}
function getPrice(p)
{
switch(p)
{
case 1: return 2.98;
case 2: return 4.50;
case 3: return 9.98;
case 4: return 4.49;
case 5: return 6.87;
}
}
</script>
</head>
<body>
<form>
<table border=0>
<tr><td><b> Product Name</td>
<td><b>Quantity Sold</td></tr>
<tr><td> Product 1</td>
<td><input id=p1></td></tr>
<tr><td> Product 2</td>
<td><input id=p2></td></tr>
<tr><td> Product 3</td>
<td><input id=p3></td></tr>
<tr><td> Product 4</td>
<td><input id=p4></td></tr>
<tr><td> Product 5</td>
<td><input id=p5></td></tr>
<tr><td colspan=2 align=center>
<input name=Calculate type=submit></td></tr>
<tr><td> Total Price</td>
<td><input id=tprice></td></tr>
</table>
</form>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.