Cash Register Program

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

Cash Register Program

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
`# 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    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 functiondef 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

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`
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Cash Register Program

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.. 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
`# 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    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 functiondef 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)`
Due to the reasons discussed here we are moving to python-forum.net on October 1, 2016.

This forum will be closed. Please create an account at the new site to continue discussion.

IRC://irc.freenode.net/python-forum
Kebap

Posts: 689
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 4 guests