Computer Science Canada Cash Register Help |
Author: | .hack [ Mon Feb 02, 2004 6:19 pm ] |
Post subject: | 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! |
Author: | santabruzer [ Mon Feb 02, 2004 6:33 pm ] | ||
Post subject: | |||
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:
|
Author: | Tony [ Mon Feb 02, 2004 6:34 pm ] | ||
Post subject: | |||
thats because you have to wait for the users to enter the values first, then calculate. Meaning
|
Author: | santabruzer [ Mon Feb 02, 2004 6:35 pm ] |
Post subject: | |
i knew this would happen, so i added the record thing |
Author: | Tony [ Mon Feb 02, 2004 6:37 pm ] |
Post subject: | |
haha santabruzer - you're killing the poor guy obviously he needs help with variable value input order and you whip out a record array |
Author: | santabruzer [ Mon Feb 02, 2004 6:38 pm ] |
Post subject: | |
i dunnu.. i just thought well since he is in gr. 11.. and he's above his class ... oh well i just like things efficient.. |
Author: | .hack [ Mon Feb 02, 2004 6:42 pm ] |
Post subject: | |
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. |
Author: | shorthair [ Mon Feb 02, 2004 6:56 pm ] |
Post subject: | |
.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 |
Author: | .hack [ Mon Feb 02, 2004 7:10 pm ] | ||||
Post subject: | |||||
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. 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:
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:
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. |
Author: | santabruzer [ Mon Feb 02, 2004 7:23 pm ] | ||
Post subject: | |||
and the "," is where?
where the massive space is.... |
Author: | shorthair [ Mon Feb 02, 2004 7:24 pm ] |
Post subject: | |
Thanks forthe quick change .hack your one of few new guys who catch on to the rules, Have Some bits when i get the ones that were stolen back |
Author: | .hack [ Mon Feb 02, 2004 7:34 pm ] |
Post subject: | |
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 ) |
Author: | .hack [ Mon Feb 02, 2004 7:59 pm ] | ||
Post subject: | |||
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...
one day I hope to be able to give back to te community, if that makes helping me seem any easier =/ |
Author: | shorthair [ Mon Feb 02, 2004 8:29 pm ] | ||
Post subject: | |||
thats your app in the simplist form , rebuild what you want from this starting poin, this one works
|
Author: | .hack [ Mon Feb 02, 2004 8:32 pm ] |
Post subject: | |
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! |
Author: | shorthair [ Mon Feb 02, 2004 8:35 pm ] |
Post subject: | |
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 |
Author: | AsianSensation [ Mon Feb 02, 2004 8:36 pm ] | ||||||
Post subject: | |||||||
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:
So when you were doing:
to fix it, you can either use locate (), or manually output some blanks. Edit: Damn it, I must really type slow. |
Author: | .hack [ Mon Feb 02, 2004 9:03 pm ] |
Post subject: | |
Thanks for everythun guys, I jsut read over the e-mail and plan on following them 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 ) |
Author: | santabruzer [ Mon Feb 02, 2004 10:28 pm ] |
Post subject: | |
well anyways.. back to records .. check out this funkii tutorial.. not by me.. by dodge_tomahawk...here |