Computer Science Canada Procedure problem |
Author: | nonamedude [ Thu May 28, 2009 7:14 pm ] | ||
Post subject: | Procedure problem | ||
What is it you are trying to achieve? A store program What is the problem you are having? The program works fine but if the user reapeats it it stops because of the procedures, (i cant use one thats not global to the rest) Describe what you have tried to solve this problem Do the whole program as one procedure but it just meeses it up NOTE: I can only use limited code to this this program(its not like i dont want to it just that i want to do it using what i studied) loops for loops procedures arrays if statements (boolean values) counters and thats about it (and the basics of course) Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using 4.1.1.0 |
Author: | Dusk Eagle [ Thu May 28, 2009 7:58 pm ] | ||||||
Post subject: | Re: Procedure problem | ||||||
First of all, your arrays should not be going from 1 to 1000. This is a terrible programming practice for many reasons. You should either make them contain only as many elements as you need, or you should use flexible arrays if you are not sure how many elements you will need. Secondly, you are using procedures wrong (but good job for using them in the first place!). Procedures should not be modifying the value of variables that are declared outside their scope (i.e. outside of themselves). You should probably look into functions and parameters here. Note that any variables a procedure relies upon that are not passed in as parameters should be declared inside the procedure itself, and not outside. As for the problem with your code, it lies right here:
One more thing: What do you think the following piece of code is supposed to do, anyway? Why are you setting time to zero every time only to increment it by one? Why does "view" have 1000 elements when you only use the first? Why do you have a loop that will always exit the first time through, assuming the user entered a positive number?
|
Author: | Dusk Eagle [ Thu May 28, 2009 7:58 pm ] | ||||||
Post subject: | Re: Procedure problem | ||||||
First of all, your arrays should not be going from 1 to 1000. This is a terrible programming practice for many reasons. You should either make them contain only as many elements as you need, or you should use flexible arrays if you are not sure how many elements you will need. Secondly, you are using procedures wrong (but good job for using them in the first place!). Procedures should not be modifying the value of variables that are declared outside their scope (i.e. outside of themselves). You should probably look into functions and parameters here. Note that any variables a procedure relies upon that are not passed in as parameters should be declared inside the procedure itself, and not outside. As for the problem with your code, it lies right here:
One more thing: What do you think the following piece of code is supposed to do, anyway? Why are you setting time to zero every time only to increment it by one? Why does "view" have 1000 elements when you only use the first? Why do you have a loop that will always exit the first time through, assuming the user entered a positive number?
|
Author: | nonamedude [ Thu May 28, 2009 8:12 pm ] |
Post subject: | Re: Procedure problem |
ok lots of questions.... gimme a sec to look things through |
Author: | nonamedude [ Thu May 28, 2009 8:20 pm ] |
Post subject: | Re: Procedure problem |
ok i dont want to set my time to 0 i want it to take time every time and add one to it.< every time it loops I tried what you said but oen problem it only displays the product that i bought, i need it to display everything... and i stote 1..1000 because i am uncertain of the amount<------ please tell me any disavantages of this vs storing it to the number of elements you need I took a look at the walkthorugh and i'd love to use those codes but i as i said before it is not that i dont want to its just i need to do it with what i learnt so far |
Author: | nonamedude [ Thu May 28, 2009 9:32 pm ] |
Post subject: | Re: Procedure problem |
If there are guys who answer i might nt be able to answer for a few hours because i wont be online |
Author: | nonamedude [ Fri May 29, 2009 12:27 pm ] |
Post subject: | Re: Procedure problem |
Anyone there? |
Author: | jbking [ Fri May 29, 2009 1:17 pm ] |
Post subject: | Re: Procedure problem |
nonamedude @ Thu May 28, 2009 6:20 pm wrote: I tried what you said but oen problem it only displays the product that i bought, i need it to display everything...
How is the procedure supposed to know all the other stuff it is supposed to show? This is where a parameter can be useful I think. |
Author: | nonamedude [ Fri May 29, 2009 7:23 pm ] |
Post subject: | Re: Procedure problem |
ok i'll try and read the parameters walkthrough but if there is a way of doing this wihtout using parameters please tell me cause i was supposed to be able to do this wthout any additional code (to the one i mentioned above) |
Author: | nonamedude [ Sat May 30, 2009 4:51 pm ] |
Post subject: | Re: Procedure problem |
Is there a way to make this work cause i am seriously stuck, i got a hint that if i use for loops and store the info in arrays it would make this much easier but i cant seem to get it right ![]() |
Author: | tjmoore1993 [ Sat May 30, 2009 5:08 pm ] | ||
Post subject: | RE:Procedure problem | ||
Use a procedure like that can help a lot because you have too many of them for such a simple program. Looping it would also work. |
Author: | nonamedude [ Sat May 30, 2009 5:14 pm ] |
Post subject: | Re: Procedure problem |
ok..... so hw would that help me with the bill<----- thats my main problem i need to display everthing the customer bought but in the end i only display what he recently bought |
Author: | tjmoore1993 [ Sat May 30, 2009 6:10 pm ] | ||
Post subject: | RE:Procedure problem | ||
Sample of what could be a better approach. Edit* Flexible arrays will help you when you are figuring out which items you bought by creating a new array each time you bought something. Why not array? Think of it this way... If someone bought 15 items or more you'd need to define a large array and it still might not be enough. Flexible array allows you to change the array allowing maximum efficiency. Figure out your program first before you do so, maybe ask questions about it as well. |
Author: | nonamedude [ Sun May 31, 2009 2:13 pm ] |
Post subject: | Re: Procedure problem |
Ok the program works fine but i dont understand any of the codes, it is nt that i want do not want to learn them but i have to be able to do this assignment withought using codes tthat i did nt study i gt arrays <--- hw to store them in arrays procedure<------ basic procedure counters loops, for loop if staments i would gradly aprreciate it if you gave me an example using these, in the meantime i'll work on the one you gave me |
Author: | tjmoore1993 [ Sun May 31, 2009 5:30 pm ] | ||
Post subject: | RE:Procedure problem | ||
I do not know how to explain this as good but guides do help and give great descriptive sentences on this stuff. Also, about the I/O portion of the code stream is basically another word for moving data (in and out). When you want to retrieve data you can use a 'read' or 'get' statement or vice versa 'write' or 'put'. Boolean is another way of saying 'true' or 'false'. Also notice how in the procedure when I give it a number it loads that file thus allowing ultimate efficiency because you do not need to load things you will probably not look at but load things when you want to see them. |
Author: | nonamedude [ Sun May 31, 2009 9:22 pm ] |
Post subject: | Re: Procedure problem |
TY very much this helps a lot |