Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

transaction part of a cash register program 3

Status
Not open for further replies.

obobob

Technical User
Oct 20, 2002
112
CA
Hi all,
I am a new qbasic student
I am trying to run this transaction part of a cash register program, but when I run it the output is all zeros! can anyone tell me what I am doing wrong
any input will be appreciated

pdata: 'sample of inventory data
DATA 125, "nails", 1.25, 2.22, 1.69, "N", "Y", 1200

tdata:
DATA 1, 392, 1 'sample of my transaction data


TYPE product
x AS INTEGER
id AS INTEGER
nam AS STRING * 20
cost AS SINGLE
price AS SINGLE
sprice AS SINGLE
sale AS STRING * 1
tax AS STRING * 1
qty AS INTEGER
END TYPE

TYPE reciept
x AS INTEGER
id AS INTEGER
scode AS INTEGER
nam AS STRING * 20
qty AS INTEGER
price AS SINGLE
tcost AS SINGLE
END TYPE

DIM pr AS product
DIM bill AS reciept
DIM count AS INTEGER
count = 0

RESTORE pdata
FOR i = 1 TO 9 STEP 1 'here I loaded all product information in pr
READ id, nam$, cost, price, sprice, sale$, tax$, qty
NEXT

FOR i = 0 TO count STEP 1'outputs bill
PRINT bill.nam; (i); " "; bill.price; (i); " "; bill.qty; (i)
NEXT

PRINT bill.tcost

SLEEP 10 'this command just pauses the program for 10 seconds
END



SUB trans
RESTORE t1data
FOR j = 1 TO 22 STEP 1 'loading transaction info
READ scode, id, qty

FOR i = 1 TO 9 STEP 1
IF id = id THEN 'checking for id match
nam = nam 'copying name of product to bill
qty = qty - billqty 'updating qty of product

IF prsale$ = "Y" THEN 'checks if item is on sale
billprice = prsprice 'sets bill price to sale price if on sale
ELSE
billprice = prprice
END IF

IF prtax$ = "Y" THEN 'checks if there is tax
billprice = billprice * 1.15 'adjust price for tax (15%)
END IF

billtcost = billtcost + billqty * billprice 'update total cost
count = count + 1
END IF
NEXT
NEXT
END SUB
 
I won't give you the direct answer; but will tell you where to start looking.

Pay attention to your looping code; in particular:

[red]
RESTORE pdata
FOR i = 1 TO 9 STEP 1 'here I loaded all product information in pr
READ id, nam$, cost, price, sprice, sale$, tax$, qty
NEXT
[/red]

Remember that READ will store empty/zero values if it can't find any more DATA lines.

HTH
--MiggyD
 
I don't understand a part of your program, won't 'IF id = id THEN' always give you a TRUE result? And nam = nam, you shouldn't need.

I don't use READ so I'm not sure if there is something different for it, but shouldn't those variables be SHARED? Variables don't carry over into SUBs
 
I didn't even look at the sub cause I saw A big problem in the main code that will spawn other problems.

Good catch qbasicking. [thumbsup]
--MiggyD
 
This doesn't hinder your code any, but I thought that you should know that in this code:
FOR i = 1 TO 9 STEP 1
READ id, nam$, cost, price, sprice, sale$, tax$, qty
NEXT

you don't need to specify STEP 1, qbasic sets the default STEP at 1. So you could say
FOR i = 1 TO 9
READ id, nam$, cost, price, sprice, sale$, tax$, qty
NEXT

and it would work the same way.

This is the source to some of your problems (why everything appears zero). Heres my question to you: How many things does it need to READ? and how many does your program READ by looping 1 TO 9?
 
That's what I'm saying. That's the first area of problem(s) I came across.

--MiggyD
 
Just to make sure you know what everyone is talking about... ;-)

RESTORE pdata
FOR i = 1 TO 9
READ id, nam$, cost, price, sprice, sale$, tax$, qty
NEXT


Is the same as this...
RESTORE pdata
READ id, nam$, cost, price, sprice, sale$, tax$, qty
READ id, nam$, cost, price, sprice, sale$, tax$, qty
READ id, nam$, cost, price, sprice, sale$, tax$, qty
READ id, nam$, cost, price, sprice, sale$, tax$, qty
READ id, nam$, cost, price, sprice, sale$, tax$, qty
READ id, nam$, cost, price, sprice, sale$, tax$, qty
READ id, nam$, cost, price, sprice, sale$, tax$, qty
READ id, nam$, cost, price, sprice, sale$, tax$, qty
READ id, nam$, cost, price, sprice, sale$, tax$, qty


id, nam$, cost, price, sprice, sale$, tax$ and qty can only hold 1 value each...

and the way you have it set up...

pdata: 'sample of inventory data
DATA 125, "nails", 1.25, 2.22, 1.69, "N", "Y", 1200

tdata:
DATA 1, 392, 1 'sample of my transaction data


When you use Restore pdata, it sets the data pointer to the pdata label, when it is done reading that it will read the tdata, then 0's...

so this is what the Read is returning right now...

Code:
      id,    nam$, cost, price, sprice, sale$, tax$,  qty
---------------------------------------------------------
Read 125, "nails", 1.25,  2.22,   1.69,   "N",  "Y", 1200
Read   1,     392,    1,     0,      0,     0,    0,    0
Read   0,       0,    0,     0,      0,     0,    0,    0
Read   0,       0,    0,     0,      0,     0,    0,    0
Read   0,       0,    0,     0,      0,     0,    0,    0
Read   0,       0,    0,     0,      0,     0,    0,    0
Read   0,       0,    0,     0,      0,     0,    0,    0
Read   0,       0,    0,     0,      0,     0,    0,    0
Read   0,       0,    0,     0,      0,     0,    0,    0

So you might want to think about how many times you need to read the data ;-)

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Hey obobob;

It would be good to have some input on this.

It's been about 2 weeks since your original post, and I know you were here on Dec 12. Let us know if you have found your answer(s) or if there's something you can't quite grasp.
 
thanks all and sorry for not replying to all of you.
you were of great help to me, it finaly worked with your help and with some help from my teacher so thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top