By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,002 Members | 1,171 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,002 IT Pros & Developers. It's quick & easy.

Cash Register

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 2004-05-11T18:32:33Z, RQ******@optonline.net (Ryan Q.) writes:
It works, i'm just posting it hoping someone could do better.
Of that I'm sure. :-)
while b != 0:


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.
http://www.strausergroup.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAoTBY5sRg+Y0CpvERAtA1AJ43lt8H7JpoZu0snjAM29 9mn1CIiwCeIhd3
uCTxtus9K7uemQ9/4xozk30=
=OJ21
-----END PGP SIGNATURE-----
Jul 18 '05 #2

P: n/a
Ryan Q. wrote:
It works, i'm just posting it hoping someone could do better.

print ''
print ' *** CASH REGISTER ***'
print ' PRESS 0 AND THEN ENTER TO TOTAL'


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
http://www.cosc.canterbury.ac.nz/~greg

Jul 18 '05 #3

P: n/a
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." <RQ******@optonline.net> wrote in message
news:d1**************************@posting.google.c om...
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 SALES $ ',v

Jul 18 '05 #4

P: n/a
Greg Ewing <gr**@cosc.canterbury.ac.nz> wrote:
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)


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
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.