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

Username:   Password: 
 RegisterRegister   
 How to make 2d/3d int arrays in turing
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ynotpeace




PostPosted: Tue Jan 05, 2010 6:20 pm   Post subject: How to make 2d/3d int arrays in turing

What is it you are trying to achieve?

I am trying to make a 2d/ 3d int array but dont know how. can anyone help me?

What is the problem you are having?
<Answer Here>


Describe what you have tried to solve this problem
<Answer Here>


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


<Add your code here>



Please specify what version of Turing you are using
latest one
Sponsor
Sponsor
Sponsor
sponsor
registration




PostPosted: Tue Jan 05, 2010 6:23 pm   Post subject: Re: How to make 2d/3d int arrays in turing

2D arrays:
var variableName : array low .. high, low2 .. high2 of type := init ()

not sure about 3D arrays.. why would you even need such a thing in turing?
Zren




PostPosted: Tue Jan 05, 2010 8:14 pm   Post subject: RE:How to make 2d/3d int arrays in turing

Basically Mutidemsional arrays just add the extra , low3 .. high3.

Turing:

const size := 3
var cube : array 1 .. size, 1 .. size, 1 .. size of int

for z : 1 .. size
    for y : 1 .. size
        for x : 1 .. size
            cube (x, y, z) := Rand.Int (0, 9)
        end for
    end for
end for

for z : 1 .. size
    for y : 1 .. size
        for x : 1 .. size
            put cube (x, y, z), "" ..
        end for
        put ""
    end for
    put ""
end for
DtY




PostPosted: Tue Jan 05, 2010 8:51 pm   Post subject: RE:How to make 2d/3d int arrays in turing

You can also use the more literal syntax, this is the same example as Zren gave:

Turing:
const size := 3
var cube: array 1..size of array 1..size of array 1..size of int


They both mean the same thing, except this version is more literal, the other is often easier to read.

When accessing them, you can index them with `cube(x,y,z)`, or `cube(x)(y)(z)`.
The second one actually makes more sense, imo.
ynotpeace




PostPosted: Tue Jan 05, 2010 8:59 pm   Post subject: Re: How to make 2d/3d int arrays in turing

Thanks for all your help.
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 1  [ 5 Posts ]
Jump to:   


Style:  
Search: