Cash Register

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ryan Q.

    Cash Register

    It works, i'm just posting it hoping someone could do better.

    print ''
    print ' *** CASH REGISTER ***'
    print ' PRESS 0 AND THEN ENTER TO TOTAL'
    b = 1
    t = 0
    v = 0
    while b != 0:
    a = 1
    s = 0
    print ''
    while a != 0:
    a = input(' ITEM $ ')
    s = s + a
    print ' TOTAL $',s
    v = v + s
    cash = input(' CASH $ ')
    change = cash - s
    print ' CHANGE $',change
    print ' '
    print ' TOTAL SLAES $ ',v
  • Kirk Strauser

    #2
    Re: Cash Register

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    At 2004-05-11T18:32:33Z, RQuinn15@optonl ine.net (Ryan Q.) writes:
    [color=blue]
    > It works, i'm just posting it hoping someone could do better.[/color]

    Of that I'm sure. :-)
    [color=blue]
    > while b != 0:[/color]

    b never goes to 0.

    Your variables have meaningless names.

    You misspelled 'SALES'.

    I would not give that a high grade.
    - --
    Kirk Strauser
    The Strauser Group
    Open. Solutions. Simple.

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)

    iD8DBQFAoTBY5sR g+Y0CpvERAtA1AJ 43lt8H7JpoZu0sn jAM299mn1CIiwCe Ihd3
    uCTxtus9K7uemQ9/4xozk30=
    =OJ21
    -----END PGP SIGNATURE-----

    Comment

    • Greg Ewing

      #3
      Re: Cash Register

      Ryan Q. wrote:[color=blue]
      > It works, i'm just posting it hoping someone could do better.
      >
      > print ''
      > print ' *** CASH REGISTER ***'
      > print ' PRESS 0 AND THEN ENTER TO TOTAL'[/color]

      I notice it's nicely agnostic about what kind
      of numbers are used. This will come in very handy
      if complex currency is ever introduced...

      ITEM $ 3.50
      ITEM $ 2.30j
      ITEM $ 1+2j
      ITEM $ 0
      TOTAL $ (4.5+4.3j)
      CASH $ 50
      CHANGE $ (45.5-4.3j)

      TOTAL SLAES $ (4.5+4.3j)

      --
      Greg Ewing, Computer Science Dept,
      University of Canterbury,
      Christchurch, New Zealand


      Comment

      • Larry Bates

        #4
        Re: Cash Register

        Let's see:

        1) If user inputs text, program crashes (not good)
        Probably should use raw_input and put float() inside
        a try block.

        2) I can't figure out how program ever stops (e.g. b
        is set to 1 and never reset to exit the while b!=0
        loop).

        3) Sales is mispelled in the last print statement

        4) Use inplace incrementing (e.g. v+=s, s+=a)
        instead of s=s+a, v=v+s

        5) What is t variable used for?

        Good Luck.

        "Ryan Q." <RQuinn15@opton line.net> wrote in message
        news:d1bd056c.0 405111032.3b2c4 11f@posting.goo gle.com...[color=blue]
        > It works, i'm just posting it hoping someone could do better.
        >
        > print ''
        > print ' *** CASH REGISTER ***'
        > print ' PRESS 0 AND THEN ENTER TO TOTAL'
        > b = 1
        > t = 0
        > v = 0
        > while b != 0:
        > a = 1
        > s = 0
        > print ''
        > while a != 0:
        > a = input(' ITEM $ ')
        > s = s + a
        > print ' TOTAL $',s
        > v = v + s
        > cash = input(' CASH $ ')
        > change = cash - s
        > print ' CHANGE $',change[/color]
        [color=blue]
        > print ' '
        > print ' TOTAL SALES $ ',v[/color]


        Comment

        • Martin Maney

          #5
          Re: Cash Register

          Greg Ewing <greg@cosc.cant erbury.ac.nz> wrote:[color=blue]
          > I notice it's nicely agnostic about what kind
          > of numbers are used. This will come in very handy
          > if complex currency is ever introduced...[/color]
          [color=blue]
          > ITEM $ 3.50
          > ITEM $ 2.30j
          > ITEM $ 1+2j
          > ITEM $ 0
          > TOTAL $ (4.5+4.3j)
          > CASH $ 50
          > CHANGE $ (45.5-4.3j)[/color]

          Beautiful demonstration of the principle behind the rule that items
          with complex prices may only be sold in conjugate pairs! :-)

          --
          automation: replacing what works with something that almost works,
          but which is faster and cheaper. - attributed to Roger Needham

          Comment

          Working...