Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Cash Register Help
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
.hack




PostPosted: 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!
Sponsor
Sponsor
Sponsor
sponsor
santabruzer




PostPosted: Mon Feb 02, 2004 6:33 pm   Post subject: (No 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:
code:

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




PostPosted: Mon Feb 02, 2004 6:34 pm   Post subject: (No subject)

thats because you have to wait for the users to enter the values first, then calculate. Meaning
code:

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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
santabruzer




PostPosted: Mon Feb 02, 2004 6:35 pm   Post subject: (No subject)

i knew this would happen, so i added the record thing Razz
Tony




PostPosted: Mon Feb 02, 2004 6:37 pm   Post subject: (No subject)

haha Laughing santabruzer - you're killing the poor guy Rolling Eyes

obviously he needs help with variable value input order and you whip out a record array Laughing
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
santabruzer




PostPosted: Mon Feb 02, 2004 6:38 pm   Post subject: (No subject)

i dunnu.. i just thought well since he is in gr. 11.. and he's above his class Embarassed ... oh well i just like things efficient.. Razz
.hack




PostPosted: Mon Feb 02, 2004 6:42 pm   Post subject: (No 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 Smile

I'll see how this goes and post the results later.

Smile
shorthair




PostPosted: Mon Feb 02, 2004 6:56 pm   Post subject: (No 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
Sponsor
Sponsor
Sponsor
sponsor
.hack




PostPosted: Mon Feb 02, 2004 7:10 pm   Post subject: (No 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. Embarassed

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:


code:
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:


code:
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




PostPosted: Mon Feb 02, 2004 7:23 pm   Post subject: (No subject)

and the "," is where?

code:
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




PostPosted: Mon Feb 02, 2004 7:24 pm   Post subject: (No subject)

Thanks forthe quick change .hack your one of few new guys who catch on to the rules, Very Happy Have Some bits when i get the ones that were stolen back
.hack




PostPosted: Mon Feb 02, 2004 7:34 pm   Post subject: (No 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 Smile

Again, apologies for the bad topic title, and for my nub coding Sad

(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 Smile )
.hack




PostPosted: Mon Feb 02, 2004 7:59 pm   Post subject: (No 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...


code:
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




PostPosted: Mon Feb 02, 2004 8:29 pm   Post subject: (No subject)

thats your app in the simplist form , rebuild what you want from this starting poin, this one works
code:

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




PostPosted: Mon Feb 02, 2004 8:32 pm   Post subject: (No subject)

thanks alot Smile after reading your code I finally caught onto what the problem was. I misunderstood how the spacing with the Sad#), worked. but now I seem to have a descent grasp.

Again I hate to bug and thanks a million!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 19 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: