Change Assignment

Change Assignment

In this program you will first successfully run the Change Template Program given to you below.  Then, piece by piece you will adapt it so that it prints out the change in dollars, quarters, dimes, nickels and pennies.  Your program should look like the following when it runs: (assume first 2 lines are prompt boxes with the underlined values what is entered by the user)

Enter purchase price:   3.33
How much was collected?:  10.00

The change is:
Dollars:  6
Quarters:  2
Dimes:  1
Nickels: 1
Pennies: 2

You can add to your program for extra credit the ability to figure sales tax, and the ability to determing $5, $10, and $20 in your change.

The template can be found at:

The HTML is found below.  It would be better to cut and paste the source code after successfully running the program above, so you know it works:

Change Template

<!– This program takes the modulus of an input number –>


<script type=”text/javascript”>
purprice = prompt(“Enter amount of purchase”,””);
purprice = parseFloat(purprice);

collected = prompt(“Enter amount collected by customer”,””);
collected = parseFloat(collected);

change = collected – purprice
document.write(“amount of change is ” + change + “<p>”);
change = parseInt(change * 100);
document.write(“the number of pennies in your change is ” + change + “<p>”);

dollars = parseInt(change / 100);

document.write(“the number of dollars in your change is ” + dollars+ “<p>”);

change = change % 100

document.write(“you still have ” + change + ” pennies left <p>”);