## Report of Sales in cash register

This is the place for queries that don't fit in any of the other categories.

### Report of Sales in cash register

For a cash register program that I am working on for a class I need to display a report of sales that displays the total quantity of each item ordered during the day which updates as orders are entered, the total sales for each item, and the grand total for sales during the day. right now it displays the report of sales, but everything is at 0. Can anyone help me witht this?

Code: Select all
`# Menudef menu():    """provides a menu for a restaurant"""    items = [("H", "Hamburger", "\$1.29"), ("O", "Onion Rings", "\$1.09"), ("C", "Cheeseburger", "\$1.49"),             ("S", "Small Drink", "\$0.79"), ("F", "Fries", "\$0.99"), ("L", "Large Drink", "\$1.19")]    for x in items:        letter, name, prices = x        print letter, "\t", name, prices    print "A\tEnd Order"    print "R\tReport of Sales"# Input Functiondef input():    """user inputs what they want"""    choice = "again"     subtotal = 0    htotal = 0    ototal = 0    ctotal = 0    stotal = 0    ftotal = 0    ltotal = 0    while choice.upper() != "A" and choice.upper() != "R":        choice = raw_input("\nEnter a letter that corresponds to what you would like to order: ")         if choice.upper() == "H":            print "Hamburger\t\$1.29"            subtotal = subtotal + 1.29            htotal = htotal + 1        elif choice.upper() == "O":            print "Onion Rings\t\$1.09"            subtotal = subtotal + 1.09            ototal = ototal + 1        elif choice.upper() == "C":            print "Cheeseburger\t\$1.49"            subtotal = subtotal + 1.49            ctotal = ctotal + 1        elif choice.upper() == "S":            print "Small Drink\t\$0.79"            subtotal = subtotal + .79            stotal = stotal + 1        elif choice.upper() == "F":            print "Fries\t\$0.99"            subtotal = subtotal + .99            ftotal = ftotal + 1        elif choice.upper() == "L":            print "Large Drink\t\$1.19"            subtotal = subtotal + 1.19            ltotal = ltotal + 1        elif choice.upper() == "A":            subtotal = subtotal        else:            print "Please enter a correct choice."    grandtotal = htotal + ototal + ctotal + stotal + ftotal + ltotal    return choice, subtotal, htotal, ototal, ctotal, stotal, ftotal, ltotal, grandtotal                #calc functiondef calc(choice, subtotal, htotal, ototal, ctotal, stotal, ftotal, ltotal, grandtotal):    """calculate"""    tax = subtotal * .05    total = subtotal + tax    print "Subtotal: ", subtotal    print "Tax: ", tax    print "Total: \$", total    amount = float(raw_input("\nEnter the amount collected: "))    if amount >= total:        change = amount - total        print "Change: \$", change    elif amount < total:        amount = float(raw_input("That is not enough money. Please reenter the amount collected: "))        change = amount - total        print "Change: \$", change    return tax   # report functiondef report(choice, subtotal, htotal, ototal, ctotal, stotal, ftotal, ltotal, grandtotal, tax):    """displays the report of sales"""    print "Item\t\t\tQuantity\tSales"    print "Hamburgers\t\t", htotal, "\t\t", htotal * 1.29    print "Cheeseburgers\t\t", ctotal, "\t\t", ctotal * 1.49    print "Fries\t\t\t", ftotal, "\t\t", ftotal * .99    print "Onion Rings\t\t", ototal, "\t\t", ototal * 1.09    print "Small Drink\t\t", stotal, "\t\t", stotal * .79    print "Large Drink\t\t", ltotal, "\t\t", ltotal * 1.19    print    print "Total Sales for Day:\t\t\t", grandtotal    print "Total Tax for Day:\t\t\t", grandtotal * tax    print "Total:\t\t\t\t\t", (grandtotal * tax) + grandtotal    # main scopechoice = "yes"while choice == "yes":    menu()    choice, subtotal, htotal, ototal, ctotal, stotal, ftotal, ltotal, grandtotal = input()    if choice.upper() == "A":        tax = calc(choice, subtotal, htotal, ototal, ctotal, stotal, ftotal, ltotal, grandtotal)    if choice.upper() == "R":        report(choice, subtotal, htotal, ototal, ctotal, stotal, ftotal, ltotal, grandtotal, tax)    choice = raw_input("\nWould you like to enter a new customer(yes/no)? ")`
jhags55

Posts: 2
Joined: Mon May 20, 2013 12:23 am

### Re: Report of Sales in cash register

My advice before doing anything else would be... learn to use dictionaries.

This kind of thing:
Code: Select all
`menu = {"H":("Hamburger",1.29),"O":("Onion Rings",1.09),"C":("Cheeseburger",1.49),        "S":("Small Drink",0.79),"F":("Fries",0.99),"L":("Large Drink",1.19)}history = {}subtotal = 0again = "y"while again == "y":    choice = ""    while choice not in menu:        choice = raw_input("Select from the menu: ").upper()    item,price = menu[choice]    print("{:15} \${:.2f}".format(item,price))    subtotal += price    history[item] = history.get(item,0)+1    again = raw_input("Press 'y' to add another item: ".lower())print("\nSubtotal: \${}\n".format(subtotal))for food,amount in history.items():    print("{:15}: {}".format(food,amount))`

Would replace all this:
Code: Select all
`if choice.upper() == "H":    print "Hamburger\t\$1.29"    subtotal = subtotal + 1.29    htotal = htotal + 1elif choice.upper() == "O":    print "Onion Rings\t\$1.09"    subtotal = subtotal + 1.09    ototal = ototal + 1elif choice.upper() == "C":    print "Cheeseburger\t\$1.49"    subtotal = subtotal + 1.49    ctotal = ctotal + 1elif choice.upper() == "S":    print "Small Drink\t\$0.79"    subtotal = subtotal + .79    stotal = stotal + 1elif choice.upper() == "F":    print "Fries\t\$0.99"    subtotal = subtotal + .99    ftotal = ftotal + 1elif choice.upper() == "L":    print "Large Drink\t\$1.19"    subtotal = subtotal + 1.19    ltotal = ltotal + 1`

-Mek
New Users, Read This
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Describe your problem; not your chosen solution.
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

### Re: Report of Sales in cash register

I would not call a global function raw_input() or input() regardless of version just because of the confusion. Not to mention overwriting the input built-in function. This wouldn't really matter in 2.x, but lets assume you converted it to 3.x. The program would overwrite the input() built-in function and would probably result in an error at worst case scenerio, on other cases it just wouldn't take the input at all.
Its essentiallys saying in 3.x in 2.x form:
Code: Select all
`def raw_input(var):    return True    choice = raw_input('test')`

Has the class taught classes yet? That would make this a breeze, but the way coded it is quite confusing:
returning that many values
Code: Select all
`choice, subtotal, htotal, ototal, ctotal, stotal, ftotal, ltotal, grandtotal = input()`

and that many args:
Code: Select all
`report(choice, subtotal, htotal, ototal, ctotal, stotal, ftotal, ltotal, grandtotal, tax)`

i beleive your problem is in the last while loop. All those variables do not retain their information between customers. Once the loop ends all that data is gone, so when you report() those values, it shows the defaults of 0. IF you change the defaults to some other number, you will see the output of that in report.
we will be moving to python-forum.io on October 1 2016
more details here

metulburr

Posts: 2244
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

### Re: Report of Sales in cash register

Yeah... all those different variable names to keep track of each item is just bad.

http://python-forum.org/viewtopic.php?f=6&t=3394

The last topic seems like it should have sufficed.

-Mek
New Users, Read This
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Describe your problem; not your chosen solution.
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona