Ask Question
30 August, 21:09

Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are dollars, quarters, dimes, nickels, and pennies. Use singular and plural coin names as appropriate, like 1 penny vs. 2 pennies. If the input is 0 or less, output: no change. If the input is 45, the output is:

1 quarter 2 dimes

+3
Answers (1)
  1. 30 August, 23:33
    0
    The program in python programming language is as follows

    amount = int (input ("Enter Amount: "))

    #Check if input is less than 1

    if amount<=0:

    print ("No Change")

    else: #If otherwise

    #Convert amount to various coins

    dollar = int (amount/100) #Convert to dollar

    amount = amount % 100 #Get remainder after conversion

    quarter = int (amount/25) #Convert to quarters

    amount = amount % 25 #Get remainder after conversion

    dime = int (amount/10) #Convert to dimes

    amount = amount % 10 #Get remainder after conversion

    nickel = int (amount/5) #Convert to nickel

    penny = amount % 5 #Get remainder after conversion

    #Print results

    if dollar > = 1:

    if dollar = = 1:

    print (str (dollar) + " dollar")

    else:

    print (str (dollar) + " dollars")

    if quarter > = 1:

    if quarter = = 1:

    print (str (quarter) + " quarter")

    else:

    print (str (quarter) + " quarters")

    if dime > = 1:

    if dime = = 1:

    print (str (dime) + " dime")

    else:

    print (str (dime) + " dimes")

    if nickel > = 1:

    if nickel = = 1:

    print (str (nickel) + " nickel")

    else:

    print (str (nickel) + " nickels")

    if penny > = 1:

    if penny = = 1:

    print (str (penny) + " penny")

    else:

    print (str (penny) + " pennies")

    Explanation:

    The program is written in python programming language and it uses comments to explain some lines

    Variable amount is declared as integer

    Line 3 checks if amount is less than or equal to 0

    If yes, the program outputs No Change

    Else, it converts the input amount to lesser coins

    Line 7 of the program gets the dollar equivalent of the input amount

    Line 8 gets the remainder

    Line 9 gets the quarter equivalent of the remainder

    Line 10 gets the remainder

    Line 11 gets the dime equivalent of the remainder

    Line 12 gets the remainder

    Line 13 gets the nickel equivalent of the remainder

    Line 14 gets the penny equivalent of the remainder

    Line 16 till the end of the program prints the output and it uses appropriates name (singular and plural)
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers