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

Username:   Password: 
 RegisterRegister   
 Procedures and arrays
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
challenger




PostPosted: Sat Jan 16, 2010 3:38 pm   Post subject: Procedures and arrays

sorry, messed up post before

What is it you are trying to achieve?
Get better understanding of procedures and arrays


What is the problem you are having?
how do you store the value of something in the procedure in an array with the mouse input


Describe what you have tried to solve this problem



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


Turing:


procedure buttonzero
    put "0"

end buttonzero

procedure buttonone
    put "1"
end buttonone


var zero : int := GUI.CreateButton (, 250, 0, "0", buttonzero)
var one : int := GUI.CreateButton (200, 200, 0, "1", buttonone)


%how do i program it so whenever i click either 0 or 1 it will store it in an array.
%ex. i click 1 then 0, so it displays 10 ( 0 in the zero index and 1 in the first index)





Please specify what version of Turing you are using
<Answer Here>
Sponsor
Sponsor
Sponsor
sponsor
Prince Pwn




PostPosted: Sun Jan 17, 2010 4:21 pm   Post subject: Re: Procedures and arrays

First, create an array like such and an index counter starting at 0

Turing:

var binaryArray : array 1 .. 10 of int
var currentIndex : int := 0


Instead of using 'put' which displays the '1' or '0' to the screen, store it in the array.

Turing:

procedure buttonzero
    binaryArray (currentIndex) := 0
end buttonzero

procedure buttonone
    binaryArray (currentIndex) := 1
end buttonone

var zero : int := GUI.CreateButton (200, 250, 0, "0", buttonzero)
var one : int := GUI.CreateButton (200, 200, 0, "1", buttonone)


To keep track of the current index, use a counter and increase it each time you click a button.

You can then use a for loop to display the array.

Turing:

for i : 1 .. length (binaryArray)
     put binaryArray (i)
end for
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  [ 2 Posts ]
Jump to:   


Style:  
Search: