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

Username:   Password: 
 RegisterRegister   
 really simple array problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
shoobyman




PostPosted: Sat Feb 11, 2006 7:33 pm   Post subject: really simple array problem

i am teh noob of teh forums, so can u guys help me?
i am trying to learn arrays, but no matter how much i try to call up the variable, it will not display it.
i can make it appear, but only if i use the "init" command.
this is my code, and each time i run it, it says that variable has no value.

code:
var number: array 1..10 of int
put number (2)
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Feb 11, 2006 7:47 pm   Post subject: (No subject)

If it says the variable has no value, it probably has a pretty good reason for saying so.

number (2) does not mean the integer, 2. It refers to the second element of an array of variables.

In this case, you have not assigned the second element (or any elements, for that matter) a value. To do so, you'd do this:
code:

number (2) := 10473

Or perhaps we could do this:
code:

for i : 1 .. 10
    number (i) := i ** 2
end for
shoobyman




PostPosted: Sat Feb 11, 2006 7:53 pm   Post subject: (No subject)

oooooooooooo, it doesn't mean integer 2, that makes more sense i just gotta declare what number (2) is, thanx! lol me is noob Laughing
MysticVegeta




PostPosted: Sat Feb 11, 2006 11:38 pm   Post subject: (No subject)

or..
code:
var nums : array 1..5 of int := init (1, 2, 3, 4, 5)
put nums(2)


Now, you wont get an error because the corresponding element at the index of 2 is 2.
Martin




PostPosted: Sun Feb 12, 2006 12:04 pm   Post subject: Re: really simple array problem

shoobyman wrote:
i am teh noob of teh forums, so can u guys help me?
i am trying to learn arrays, but no matter how much i try to call up the variable, it will not display it.
i can make it appear, but only if i use the "init" command.
this is my code, and each time i run it, it says that variable has no value.

code:
var number: array 1..10 of int
put number (2)


What your code does is creates a set of 10 integer variables.

Your code is the equivalent of:
code:
var number1: int
var number2: int
var number3: int
...
var number10: int
put number2
shoobyman




PostPosted: Sun Feb 12, 2006 6:01 pm   Post subject: (No subject)

thank you all, very helpful, i now completely understand arrays, (it wasn't nearly as hard as i thought) Very Happy Laughing .
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  [ 6 Posts ]
Jump to:   


Style:  
Search: