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

Username:   Password: 
 RegisterRegister   
 Initializing A Multidimensional Array
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
drij




PostPosted: Wed Oct 22, 2008 12:51 pm   Post subject: Initializing A Multidimensional Array

This code will not run:
Turing:
const winTypes : array 1 .. 8 of array 1 .. 3 of array 1 .. 2 of int1
:= init (1, 3, 2, 3, 3, 3,
         3, 3, 3, 2, 3, 1,
         1, 3, 1, 2, 1, 1,
         1, 1, 1, 2, 1, 3,
         1, 2, 2, 2, 3, 2,
         2, 1, 2, 2, 2, 3,
         1, 3, 2, 2, 3, 1,
         1, 1, 2, 2, 3, 3)

I have no idea what's wrong with it. I think that I should be able to initialize this array but I get the error:
'init' value is the wrong type.
Sponsor
Sponsor
Sponsor
sponsor
The_Bean




PostPosted: Wed Oct 22, 2008 1:12 pm   Post subject: Re: Initializing A Multidimensional Array

Your declaring your array wrong, the "of array" only needs to be a ",".

Turing:

const winTypes : array 1 .. 8 , 1 .. 3 , 1 .. 2 of int1
:= init (1, 3, 2, 3, 3, 3,
         3, 3, 3, 2, 3, 1,
         1, 3, 1, 2, 1, 1,
         1, 1, 1, 2, 1, 3,
         1, 2, 2, 2, 3, 2,
         2, 1, 2, 2, 2, 3,
         1, 3, 2, 2, 3, 1,
         1, 1, 2, 2, 3, 3)
[Gandalf]




PostPosted: Wed Oct 22, 2008 2:12 pm   Post subject: RE:Initializing A Multidimensional Array

The_Bean is right, however the way you are currently declaring the array could work too. After all, multidimensional arrays are just arrays of arrays. The problem is, you have a const that needs to be initialized prior to run time. You would have to explicitly use an array where each element is another array.
Tony




PostPosted: Wed Oct 22, 2008 2:44 pm   Post subject: RE:Initializing A Multidimensional Array

The syntactical difference is my_array(1)(2)(3) vs. my_array(1,2,3).

The advantage to array of array declaration is that you could get a full array as the result; the latter use requires access to a particular int1. Although this type of access is not always necessary.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
drij




PostPosted: Wed Oct 22, 2008 4:24 pm   Post subject: Re: Initializing A Multidimensional Array

Thanks guys. The_Bean's solution worked. I suppose initializing a multidimensional array declared the way had mine at the top would require the values to be specified differently. Assuming it's even possible. Smile

P.S.: In case you're wondering; this was for a tick-tac-toe game; storing all eight possible combinations of three squares that all would need to be of the same type for the game to have been won.
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: