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

Postby jhags55 » Tue May 21, 2013 1:33 pm

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
# Menu
def 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 Function
def 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 function
def 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 function
def 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 scope
choice = "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

Postby Mekire » Tue May 21, 2013 1:57 pm

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 = 0
again = "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 + 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

-Mek
User avatar
Mekire
 
Posts: 816
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Report of Sales in cash register

Postby metulburr » Tue May 21, 2013 2:03 pm

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.
New Users, Read This
version Python 3.3.2 and 2.7.5, tkinter 8.5, pyqt 4.8.4, pygame 1.9.2 pre
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
User avatar
metulburr
 
Posts: 1099
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Report of Sales in cash register

Postby Mekire » Tue May 21, 2013 2:15 pm

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

Also... why did you make a new thread about this:
http://python-forum.org/viewtopic.php?f=6&t=3394 :evil:

The last topic seems like it should have sufficed.

-Mek
User avatar
Mekire
 
Posts: 816
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests