Provide description on how to use the code.   Code is located below:  # initialize a flag variable with 0 flag = 0 # loop will execute till flag is 0 in the sense loop will execute code while flag == 0 : #until amount is greater then cost cost = float(input("Enter the cost: ")) # take input cost and convert to floating data type amount = float(input("Enter the amount given(should be greater than cost): ")) # take input if amount < cost : print("Amount should be greater than cost.") #print statement saying enter Amount that else: flag = 1 # when amount entered by user greater then cost flag is set to 1 and while loop will not execute change = amount-cost #stored difference between amount and cost to change variable print(f"The change to be given is ${change}") #print the value of change variable twenty=0 #intializing all possible coin/ notes to 0 ten=0 five=0 single=0 quarter=0 dime=0 nickel=0 penny=0 while change>=20 : #loop will execute until change become less then 20. this loop execute for change>20 twenty+=1 #incrementing twenty until change is greater than or equal to 20 change-=20 #decrementing 20 from change while change>=10 : # loop will execute until change is less then 10. this loop will execute for change(19.9999.. to 10) ten+=1#doing the above operation for all possible dollar bills change-=10 # decreasing change values by 10 while change>=5:#loop will execute until change will become less then 5. c change(9.999.. to5) five+=1 change-=5 while change>=1:#loop will execute for until change become less then 1.this loop will execute for change(4.999... to 1) single+=1 change-=1 while change>=0.25:#loop will execute for until change become less then 0.25. this loop will execute for change(0.99..to 0.25). similarly for other while loop quarter+=1 change-=0.25 while change>=0.10: dime+=1 change-=0.10 while change>=0.05:#Checking with 0 to counter precision penny+=1 nickel+=1 change-=0.05 while change>=0: #Checking with 0 to counter precision penny+=1 change-=0.01 #Displaying the results #printing all new values for different coin/notes/currency are got as change print(f"For that you require the following:") print(f"Twenty dollar bills: {twenty}") print(f"Ten dollar bills: {ten}") print(f"Five dollar bills: {five}") print(f"Single dollar bills: {single}") print(f"Quarter dollar bills: {quarter}") print(f"Dime dollar bills: {dime}") print(f"Nickle dollar bills: {nickel}") print(f"Penny dollar bills: {penny}")

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.7: Do While Loops
Problem 3E: (Misc. application) a. Write a program to reverse the digits of a positive integer number. For...
icon
Related questions
Question

Provide description on how to use the code.  

Code is located below: 

# initialize a flag variable with 0
flag = 0 # loop will execute till flag is 0 in the sense loop will execute code
while flag == 0 : #until amount is greater then cost
cost = float(input("Enter the cost: ")) # take input cost and convert to floating data type
amount = float(input("Enter the amount given(should be greater than cost): ")) # take input
if amount < cost :
print("Amount should be greater than cost.") #print statement saying enter Amount that
else:
flag = 1 # when amount entered by user greater then cost flag is set to 1 and while loop will not execute


change = amount-cost #stored difference between amount and cost to change variable
print(f"The change to be given is ${change}") #print the value of change variable

twenty=0 #intializing all possible coin/ notes to 0
ten=0
five=0
single=0
quarter=0
dime=0
nickel=0
penny=0

while change>=20 : #loop will execute until change become less then 20. this loop execute for change>20
twenty+=1 #incrementing twenty until change is greater than or equal to 20
change-=20 #decrementing 20 from change

while change>=10 : # loop will execute until change is less then 10. this loop will execute for change(19.9999.. to 10)
ten+=1#doing the above operation for all possible dollar bills
change-=10 # decreasing change values by 10

while change>=5:#loop will execute until change will become less then 5. c change(9.999.. to5)
five+=1
change-=5

while change>=1:#loop will execute for until change become less then 1.this loop will execute for change(4.999... to 1)
single+=1
change-=1

while change>=0.25:#loop will execute for until change become less then 0.25. this loop will execute for change(0.99..to 0.25). similarly for other while loop
quarter+=1
change-=0.25

while change>=0.10:
dime+=1
change-=0.10

while change>=0.05:#Checking with 0 to counter precision penny+=1
nickel+=1
change-=0.05

while change>=0: #Checking with 0 to counter precision
penny+=1
change-=0.01

#Displaying the results
#printing all new values for different coin/notes/currency are got as change
print(f"For that you require the following:")
print(f"Twenty dollar bills: {twenty}")
print(f"Ten dollar bills: {ten}")
print(f"Five dollar bills: {five}")
print(f"Single dollar bills: {single}")
print(f"Quarter dollar bills: {quarter}")
print(f"Dime dollar bills: {dime}")
print(f"Nickle dollar bills: {nickel}")
print(f"Penny dollar bills: {penny}")

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning