Author |
Message |
em010
|
Posted: Sun Dec 11, 2011 3:46 pm Post subject: parameters and arrays |
|
|
What is it you are trying to achieve?
So I need to pass an array into a procedure using a parameter and I"m not sure how to do it
What is the problem you are having?
I do not know how to pass arrays into procedures using parameters
Describe what you have tried to solve this problem
I have learned the difference between value parameters and variable parameters
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
I have an array filled from 1 to 49 that I have to pass into a shuffling procedure
and an array of six numbers to be passed into a sorting procedure |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
|
|
|
|
mirhagk
|
Posted: Sun Dec 11, 2011 4:41 pm Post subject: RE:parameters and arrays |
|
|
if the size doesn't change then you can quite simply just use
Turing: |
procedure Shuffle(cards:array 1..49 of int)
|
Obviously subsitute int for whatever type your using. You can also pass an array of unknown size using the following
Turing: |
procedure Shuffle(cards:array 1..* of int)
|
The size of the array does not need to be known by the procedure, so this will accept an array of any size (you can then determine it's size using upper). |
|
|
|
|
|
em010
|
Posted: Sun Dec 11, 2011 5:14 pm Post subject: RE:parameters and arrays |
|
|
I still need to know how you would pass the array though... like where would you put it after the procedure |
|
|
|
|
|
mirhagk
|
Posted: Sun Dec 11, 2011 8:12 pm Post subject: RE:parameters and arrays |
|
|
an array is essentially the same as any variable. It is just a variable that also happens to be a list of other variables. You treat it just like you would pass a variable |
|
|
|
|
|
Tony
|
Posted: Sun Dec 11, 2011 8:23 pm Post subject: RE:parameters and arrays |
|
|
to be more specific, array definition is a variable type and can be treated the same way as any other variable type (e.g. as int) |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
em010
|
Posted: Sun Dec 11, 2011 9:02 pm Post subject: RE:parameters and arrays |
|
|
So would you like to explain to me how to pass a variable into a procedure? |
|
|
|
|
|
Tony
|
|
|
|
|
Sponsor Sponsor
|
|
|
mirhagk
|
Posted: Sun Dec 11, 2011 10:48 pm Post subject: RE:parameters and arrays |
|
|
I have a question. How is the first thing you pass into a procedure an array? And if you've passed other things before (I'm sure you have), then you need to review that. Or just read the Turing Walkthrough topic on it. We're not here to demonstrate how to do everything, you need to learn with your teacher, or on your own. We're just here to help you when your stuck. |
|
|
|
|
|
|