Answer:
input price
set change to one hundred minus price
set quarter to change divided by 25
set change to change mod 25
set dime to change divided by 10
set change to change mod 10
set nickel to change divided by 5
set change to change mod 5
set penny to change
print "You acquired an item for price cents and paid me a dollar. Your change is: "
if quarter is equal to 1
print quarter
else if quarter is greater than 1
print quarter with "quarters"
if dime is equal to 1
print dime
else if dime is greater than 1
print dime with "dimes"
if nickel is equal to 1
print nickel
else if nickel is greater than 1
print nickel with "nickels"
if penny is equal to 1
print penny
else if penny is greater than 1
print penny with "pennies"
Explanation:
A clearer way to express the pseudocode above could involve using alternative names for change as:
input price
set change to one hundred minus price
set quarter to change divided by 25
set quarter_remainder to change mod 25
set dime to quarter_remainder divided by 10
set dimes_remainder to quarter_remainder mod 10
set nickel to dimes_remainder divided by 5
set nickel_remainder to dimes_remainder mod 5
set penny to nickel_remainder
print "You purchased an item for" price"cents and provided a dollar. Your change is: "
if quarter is equal to 1
print quarter "quarter"
else if quarter is greater than 1
print quarter "quarters"
if dime is equal to 1
print dime "dime"
else if dime is greater than 1
print dime "dimes"
if nickel is equal to 1
print nickel "nickel"
else if nickel is greater than 1
print nickel "nickels"
if penny is equal to 1
print penny "penny"
else if penny is greater than 1
print penny "pennies"
Next, I will illustrate the pseudocode through an example:
Let's assume price = 75
Thus, change = 100 - price = 100 - 75 = 25
change = 25
quarter = change/25 = 25/25 = 1
quarter = 1
quarter_remainder = change % 25 = 25%25 = 0
dime = 0/10 = 0
At this point, all additional values are 0.
The following message will be displayed on the screen:
You acquired an item for 75 cents and paid me a dollar. Your change is:
Now the program proceeds to the conditional statement
if quarter == 1
This condition holds true because the value of quarter is 1
print quarter "quarter"
Subsequently, this line will appear on the screen:
1 quarter
Thus, the full output of the pseudocode is:
You acquired an item for 75 cents and paid me a dollar. Your change is:
1 quarter