×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

transaction part of a cash register program
3

transaction part of a cash register program

transaction part of a cash register program

(OP)
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

RE: transaction part of a cash register program

I won't give you the direct answer; but will tell you where to start looking.

Pay attention to your looping code; in particular:


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


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

HTH
--MiggyD

RE: transaction part of a cash register program

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

RE: transaction part of a cash register program

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.
--MiggyD

RE: transaction part of a cash register program

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?

RE: transaction part of a cash register program

That's what I'm saying.  That's the first area of problem(s) I came across.

--MiggyD

RE: transaction part of a cash register program

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...

      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

http://cubee.topcities.com

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

RE: transaction part of a cash register program

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.

RE: transaction part of a cash register program

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close