Cash Register Program

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

Cash Register Program

Postby jhags55 » Mon May 20, 2013 12:28 am

Hi, I am making a cash register program for a class I am in, and everything is fine with my program except for one part. I need to add a question that states: "Would you like to enter a new customer(yes/no)?" and then if they enter yes, the program should start over at the beginning but I am not quite sure how to do that. Can anyone help me with this? Here is my code:

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
    while choice.upper() != "A":
        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
        elif choice.upper() == "O":
            print "Onion Rings\t$1.09"
            subtotal = subtotal + 1.09
        elif choice.upper() == "C":
            print "Cheeseburger\t$1.49"
            subtotal = subtotal + 1.49
        elif choice.upper() == "S":
            print "Small Drink\t$0.79"
            subtotal = subtotal + .79
        elif choice.upper() == "F":
            print "Fries\t$0.99"
            subtotal = subtotal + .99
        elif choice.upper() == "L":
            print "Large Drink\t$1.19"
            subtotal = subtotal + 1.19
        elif choice.upper() == "A":
            subtotal = subtotal
        else:
            print "Please enter a correct choice"
    return choice, subtotal

           

   
#calc function
def calc(choice, subtotal):
    """calculate"""
    tax = subtotal * .05
    total = subtotal + tax
    print "Subtotal: ", subtotal
    print "Tax: ", tax
    print "Total: $", total
    amount = float(raw_input("\nEnter the amount collected: "))
    change = amount - total
    print "Change: $", change

       
menu()
choice, subtotal = input()
calc(choice, subtotal)
jhags55
 
Posts: 2
Joined: Mon May 20, 2013 12:23 am

Re: Cash Register Program

Postby micseydel » Mon May 20, 2013 3:07 am

Code: Select all
choice = 'yes'
while choice == 'yes':
    menu()
    choice, subtotal = input()
    calc(choice, subtotal)

    choice = ask() # you should be able to fill things in from here
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 923
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Cash Register Program

Postby Kebap » Mon May 20, 2013 11:36 pm

Welcome to the forums! Nice job on that code. Just one info: It is no good idea to name your function like something that already exists, like "input()". This can become confusing quickly.. :D Hope you enjoy your class!
jhags55 wrote:Hi, I am making a cash register program for a class I am in, and everything is fine with my program except for one part. I need to add a question that states: "Would you like to enter a new customer(yes/no)?" and then if they enter yes, the program should start over at the beginning but I am not quite sure how to do that. Can anyone help me with this? Here is my code:

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
    while choice.upper() != "A":
        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
        elif choice.upper() == "O":
            print "Onion Rings\t$1.09"
            subtotal = subtotal + 1.09
        elif choice.upper() == "C":
            print "Cheeseburger\t$1.49"
            subtotal = subtotal + 1.49
        elif choice.upper() == "S":
            print "Small Drink\t$0.79"
            subtotal = subtotal + .79
        elif choice.upper() == "F":
            print "Fries\t$0.99"
            subtotal = subtotal + .99
        elif choice.upper() == "L":
            print "Large Drink\t$1.19"
            subtotal = subtotal + 1.19
        elif choice.upper() == "A":
            subtotal = subtotal
        else:
            print "Please enter a correct choice"
    return choice, subtotal

           

   
#calc function
def calc(choice, subtotal):
    """calculate"""
    tax = subtotal * .05
    total = subtotal + tax
    print "Subtotal: ", subtotal
    print "Tax: ", tax
    print "Total: $", total
    amount = float(raw_input("\nEnter the amount collected: "))
    change = amount - total
    print "Change: $", change

       
menu()
choice, subtotal = input()
calc(choice, subtotal)
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 282
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot] and 1 guest