
-----------------------------------
.hack
Mon Feb 02, 2004 6:19 pm

Cash Register Help
-----------------------------------
Well, I'm in grade 11 and our programming course is turing. I'm actually quite a bit farther ahead then my class and I am working on much more advanced programs then what they are they actually doing, which is why I can't get much help from them. Anyways, this is my first program that actual does something useful (Most of mine has been smple 5+5= type things, this is the 1st prog I have done attempting vars etc)

Anyways, I'm trying to make a cash register and trying to crate a cost variable, which is Quantity * Price, thus equalling cost, becasue the cost and the quantity is user defined I can't set it as a simple multiplication code. Anyways this is the code I am mainy stuck on, I will paste the whole code farther below..

-------------Code----------------

var item1 : string
var item2 : string
var item3 : string
var item4 : string

var quan1 : int
var quan2 : int
var quan3 : int
var quan4 : int

var price1 : real
var price2 : real
var price3 : real
var price4 : real

var cost1 : real
var cost2 : real
var cost3 : real
var cost4 : real


cost1:= quan1*price1  %This Line gives me the Error(This text is not in the actual code...)
cost2:= quan2*price2
cost3:= quan3*price3
cost4:= quan4*price4
--------------end code-------------

above is mainly my list of vars (I didn't use arrays which would probably be a half decent idea. Anyways Cost1:= isn't compiling correctly, I get a variable is not defined error. I'm sure this is another n00b mistake but i can't figure it out...

the rest of the programs code is as follows....

var item1 : string
var item2 : string
var item3 : string
var item4 : string

var quan1 : int
var quan2 : int
var quan3 : int
var quan4 : int

var price1 : real
var price2 : real
var price3 : real
var price4 : real

var cost1 : real
var cost2 : real
var cost3 : real
var cost4 : real


cost1:= quan1*price1
cost2:= quan2*price2
cost3:= quan3*price3
cost4:= quan4*price4

%*******End of Var List******

%*******Start Of Coding*******

put "Enter Purchased Item"
get item1
put "Enter Quantity"
get quan1
put "Enter Price Per Unit"
get price1

put "Enter Purchased Item"
get item2
put "Enter Quantity"
get quan2
put "Enter Price Per Unit"
get price2

put "Enter Purchased Item"
get item3
put "Enter Quantity"
get quan3
put "Enter Price Per Unit"
get price3

put "Enter Purchased Item"
get item4
put "Enter Quantity"
get quan4
put "Enter Price Per Unit"
get price4

%*******Start Of Equations*********%

put item1..
put "x"..
put quan1..
put " ="
put cost1..

put item2..
put "x"..
put quan2..
put " ="..
put cost2

put item3
put " x"..
put quan3..
put " ="..
put cost3

put item4
put " x"..
put quan4..
put cost4



As you can see its not quite done yet.


Anyways if u can help me fix my cost1 problem that would be appreciated. Thanks for your time!

-----------------------------------
santabruzer
Mon Feb 02, 2004 6:33 pm


-----------------------------------
it is because your "quan1" and "price1" don't have a value... basically taht means that they have nothing to multiply.. plus another thing... why not use a record for this:

type itemlist :
    record
    itemname : string
    quan : int
    cost, price : real
    end record

var item : array 1 .. 4 of itemlist 

% Then to call upon a quan or item or cost simply:
item (1) .itemname := "a"
item (1) .quan := 3
item (2) .price := 1.5 

% Then you could do this: (Obviously after you had assigned some sort of value to this variables
for i : 1 .. 4
    item (i). cost := item (i). cost * item (i). quan
end for

-----------------------------------
Tony
Mon Feb 02, 2004 6:34 pm


-----------------------------------
thats because you have to wait for the users to enter the values first, then calculate. Meaning

var price:int
var quantity:int
var cost:int

put "enter price"
get price
put "enter quantity"
get quantity

cost := price*quantity
put "your price is: ", price


-----------------------------------
santabruzer
Mon Feb 02, 2004 6:35 pm


-----------------------------------
i knew this would happen, so i added the record thing :P

-----------------------------------
Tony
Mon Feb 02, 2004 6:37 pm


-----------------------------------
haha :lol: santabruzer - you're killing the poor guy :roll:

obviously he needs help with variable value input order and you whip out a record array :lol:

-----------------------------------
santabruzer
Mon Feb 02, 2004 6:38 pm


-----------------------------------
i dunnu.. i just thought well since he is in gr. 11.. and he's above his class  :oops: ... oh well i just like things efficient.. :P

-----------------------------------
.hack
Mon Feb 02, 2004 6:42 pm


-----------------------------------
hehe thanks for all the help guys, yea the record stuff is still quite a bit out of my ball park, by the end of today I hope to have a working cash register. Thanks for the suggestions and the help :)

I'll see how this goes and post the results later. 

:)

-----------------------------------
shorthair
Mon Feb 02, 2004 6:56 pm


-----------------------------------
.hack id like to leyt you know , that tony was easy one you and didnt say anything , but you will probably be warned by asian, if you have a problem label the thread topic apropriatly , it would be awsome if you could change the topic name ot suit your problem , that way if others hae a similar problem htey know where to look , if you came here and every thread was called help , where would you look ? , Tony you should know better ,usually ther is a no help policcy if you dont follow the rules , but your new so i wont flame you yet

-----------------------------------
.hack
Mon Feb 02, 2004 7:10 pm


-----------------------------------
I know, I realised this after I had posted and am kicking myself in the arse. I've gone throught he forums a bit more and now see how much thats frowned upon.  :oops: 

Well, I seem to have another problem.

I have 6 errors, but what I belive are solved with one step. I took Tonys advice (not that santa's isn't appreciated, I just don't want to get in too too deep tonight), and maybe I will need the record coding for the next part. 

I want it to list the Item, Quantity, Price /unit and total along the top, I have it all laid out, but again my cost vars are giving me trouble.


I went back and changed my code, so when getting the values, cost1, 2,3 and 4 are figured out after each set of values is entered, in order. But its like turing is not remember the numbers cost1, 2,3 and 4 were given previously. Heres a bit of the modded code for perhaps a better understanding:


put "Enter Purchased Item"
get item1
put "Enter Quantity"
get quan1
put "Enter Price Per Unit"
get price1

cost1 := price1*quan1

put "   "

put "Enter Purchased Item"
get item2
put "Enter Quantity"
get quan2
put "Enter Price Per Unit"
get price2

cost2 := price2*quan2

And it goes on like that for Costs 3 and 4. But when I try to list it like I had explained above, I get more errors:


put "Item" : 12, "Quantity" : 15, "Price/Unit" : 15, "Total"
put "   "
put item1 : 12, quan1 : 15, price1 :15 cost1
put "   "
put item2 : 12, quan2 : 15, price2 :15 cost2
put "   "
put item3 : 12, quan3 : 15, price3 :15 cost3
put "   "
put item4 : 12, quan4 : 15, price4 :15 cost4

that is how it should right out, so it has the headers across, then the actual numbers below in columns. unfortunately when it tries to compile the cost vars I get "cost1 is not a procedure, and hence cannot be called"

To me, its like the compiler doesn't remember the values the cost vars were given from the calculations above =/

I really hope this isn't a typo or anything. Sorry for wasting your time, this probably looks incredibly nubbish to you.

-----------------------------------
santabruzer
Mon Feb 02, 2004 7:23 pm


-----------------------------------
and the "," is where?

put "Item" : 12, "Quantity" : 15, "Price/Unit" : 15, "Total"
put "   "
put item1 : 12, quan1 : 15, price1 :15    ,       cost1
put "   "
put item2 : 12, quan2 : 15, price2 :15    ,       cost2


where the massive space is....

-----------------------------------
shorthair
Mon Feb 02, 2004 7:24 pm


-----------------------------------
Thanks forthe quick change .hack your one of few new guys  who catch on to the rules,  :D  Have Some bits when i get the ones that were stolen back

-----------------------------------
.hack
Mon Feb 02, 2004 7:34 pm


-----------------------------------
thanks for all the help, I can't believe I missed something as simple as that >.<

The program runs great so far, lets see what else I can add :)

Again, apologies for the bad topic title, and for my nub coding :(

(I read the code like 6 times and sent it to my friend to see if he could find anything wrong with it, we were both at a loss :) )

-----------------------------------
.hack
Mon Feb 02, 2004 7:59 pm


-----------------------------------
Guess whos back...

...ugh I hate posting 300000 help weeps in like an hour, but I seriously tinkered and searched through this code and did anything I thought would be right, now it appears to be an error in the exec, not the actual code. Somewhere an equation is messed up, and I semi figured out why, but don't see where...


it appears that the variables price 1, price 2, price 3 and price 4 have merged with those of cost.

Example. If I enter Apples as the item, 4 as the quantity and 10 per unit, the price per unit on the output(for a "receipt") claims its 1040. its like the price multiples the quantity then adds that to the price times itself or 10.

Here is the code...All of it, run it through your turning compiler if its open and see what happens...


var item1 : string
var item2 : string
var item3 : string
var item4 : string

var quan1 : real
var quan2 : real
var quan3 : real
var quan4 : real

var price1 : real
var price2 : real
var price3 : real
var price4 : real

var cost1 : real
var cost2 : real
var cost3 : real
var cost4 : real

%*******End of Var List******

%*******Start Of Coding*******

put "Enter Purchased Item"
get item1
put "Enter Quantity"
get quan1
put "Enter Price Per Unit"
get price1

cost1 := price1*quan1

put "   "

put "Enter Purchased Item"
get item2
put "Enter Quantity"
get quan2
put "Enter Price Per Unit"
get price2

cost2 := price2*quan2

put " "

put "Enter Purchased Item"
get item3
put "Enter Quantity"
get quan3
put "Enter Price Per Unit"
get price3

cost3 := price3*quan3

put "  "

put "Enter Purchased Item"
get item4
put "Enter Quantity"
get quan4
put "Enter Price Per Unit"
get price4

cost4 := price4*quan4

%*******Start Of Equations*********%

put "Item" : 12, "Quantity" : 15, "Price/Unit" : 15, "Total"
put "   "
put item1 : 10, quan1 : 10, price1 : 10, cost1
put "   "
put item2 : 10, quan2 : 10, price2 : 10, cost2
put "   "
put item3 : 10, quan3 : 10, price3 : 10, cost3
put "   "
put item4 : 10, quan4 : 10, price4 : 10, cost4

put "   "
put "   "
put "Total without tax is "..
put cost1 + cost2 + cost3 + cost4
put "total with tax is "..
put (cost1 + cost2 + cost3 + cost4 ) * 1.15

one day I hope to be able to give back to te community, if that makes helping me seem any easier =/

-----------------------------------
shorthair
Mon Feb 02, 2004 8:29 pm


-----------------------------------
thats your app in the simplist form , rebuild what you want from this starting poin, this one works

var item : string
var quan, price, cost : real
item := ""
quan := 0
price := 0
cost := 0
%*******Start*******
    put "Enter Purchased Item"
    get item
    put "Enter Quantity"
    get quan
    put "Enter Price Per Unit"
    get price
cost := price * quan
%*******Start Of Equations*********%

put "Item" : 12, "Quantity" : 15, "Price/Unit" : 15, "Total"

put item : 10, quan : 10, price : 15, cost:10
put "Total without tax is " ..
put cost
put "total with tax is " ..
put cost * 1.15


-----------------------------------
.hack
Mon Feb 02, 2004 8:32 pm


-----------------------------------
thanks alot :) after reading your code I finally caught onto what the problem was. I misunderstood how the spacing with the :(#), worked. but now I seem to have a descent grasp.

Again I hate to bug and thanks a million!

-----------------------------------
shorthair
Mon Feb 02, 2004 8:35 pm


-----------------------------------
not a problem im glad to help , as long as you are polite and post good topics that have not been discussed before , if you dont wnna get caught red handed ,Hacker dan the Crazy Admin here , was nice enough to retype compscis rules , this is the link to the new rules , just take a glance so you know the do's and dont's , good luck with programming and i hope you keep up hte code , always ask s oyou dont get bad habbits , and start grouping those variable to save code and time, and save your bits  (a word of the wise )

http://www.compsci.ca/v2/viewtopic.php?t=3151 ,  : Link to new rules

-----------------------------------
AsianSensation
Mon Feb 02, 2004 8:36 pm


-----------------------------------
the problem with your code is the way you formatted. 

if you declare a variable, let's call it num, as real, then when you go and try to do: put num : 10 turing, on your output screem, will allocate 10 spots for you, and then right align the number once it has rounded it off to 7 characters long. Ex. var num := 2.3253243253264325324
put num : 10 This will outputs 2.325324 and then right aligned to a 10 character long space.

So when you were doing: put item1 : 10, quan1 : 10, price1 : 10, cost1 Some of the numbers were intruding on another number's allocated space, so weird stuff happens.

to fix it, you can either use locate (), or manually output some blanks.

Edit: Damn it, I must really type slow.

-----------------------------------
.hack
Mon Feb 02, 2004 9:03 pm


-----------------------------------
Thanks for everythun guys, I jsut read over the e-mail and plan on following them :P

Most of it is about spam which is something I can't stand,, so I don't think you guys will see much from me (even though this post is very short).

Anyways I'm going to work on my cash register a bit more at school tomorrow when I have the teacher to give me a hand, I'm hoping that one day soon it will be a full fledged little cash register program (maybe I can make some $$ off it and Turing in grade 11 will be good for something :) )

-----------------------------------
santabruzer
Mon Feb 02, 2004 10:28 pm


-----------------------------------
well anyways.. back to records :P.. check out this funkii tutorial.. not by me.. by dodge_tomahawk...[url=http://www.compsci.ca/v2/viewtopic.php?t=2325]here
