'''Initial Cash Register program.  This was a challenge on Freecodecamp.org.  the original challenge is for Javascript,
but as you can see, I've done it in python.  I'll make a javascript version later as I become more comfortable in that language.

Thomas Alleman-7/22/17 '''

cid={"PENNY":1.01,"NICKEL":2.05,"DIME":3.10,"QUARTER":4.25,"ONE":90.0,"FIVE":55.0,"TEN":20.0,"TWENTY":80.0,"ONE HUNDRED":100.0}
price=3.26
cash=100

def checkCashRegister(price,cash,cid):
    inichange={"PENNY":0,"NICKEL":0,"DIME":0,"QUARTER":0,"ONE":0,"FIVE":0,"TEN":0,"TWENTY":0,"ONE HUNDRED":0}
    monvalues={"ONE HUNDRED":100.0,"TWENTY":20.0,"TEN":10.0,"FIVE":5.0,"ONE":1.0,"QUARTER":.25,"DIME":.1,"NICKEL":.05,"PENNY":0.01,}
    changedue=cash-price
    change={}
    cashcheck="empty"

    for i in monvalues:      #monvalues is a dict of currency and value
        denom=monvalues[i]   #denom sets currency value
        myset=i              #myset sets currency name
        while cid[myset]!=0 and changedue>=denom:  #iterates through currency
            inichange[myset]=round(inichange[myset]+denom,2) #python 3 dictionaries
            cid[myset]=round(cid[myset]-denom,2)             #are ordered now
            changedue=round(changedue-denom,2)

    if changedue!=0:
        return "Insufficient Funds"  #if correct change cannont be made

    for i in cid:
        if cid[i]!=0:
            cashcheck="full"   #change to full if any money in drawer
    if cashcheck=="empty":     #If cash drawer is empty, function returns "closed"
        return "Closed"

    for i in inichange:       #give change{} all non 0 values from inichange
        if inichange[i]!=0:
            change[i]=inichange[i]
    return change             #returns the exact change due

print (checkCashRegister(price,cash,cid))
