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

Username:   Password: 
 RegisterRegister   
 Saving a variable as a variable??
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Lucas




PostPosted: Thu Mar 24, 2011 7:01 pm   Post subject: Saving a variable as a variable??

What is it you are trying to achieve?
I would like to save a number to two different variables, and make it so that if i change the value of one variable, the value of the other variable changes as well


What is the problem you are having?
not sure how do this


Describe what you have tried to solve this problem
asking you guys Smile


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


Turing:


% this is just an example
var a, b : int
a := 55
b := a       % I would like it so that it would equal to the variable a, not the value of a. possible?
a := 40
put b         % This would ideally output 40, since b = a = 40



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Mar 24, 2011 7:16 pm   Post subject: RE:Saving a variable as a variable??

you are looking for pointers
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
z_cross_fire




PostPosted: Thu Mar 24, 2011 7:56 pm   Post subject: Re: Saving a variable as a variable??

I haven't heard of pointers...and I haven't learnt turing, so this is what I did in C# (if anyone can convert it to turing, it would be helpful to OP)

First, I created a class called SameValue:

code:

namespace ConsoleApplication2
{
    class SameValue
    {
        public int val;
    }
}


This is the Main Program:

code:

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            SameValue a = new SameValue();
            SameValue b = a;

            a.val = 5;
            b.val = 10;

            Console.WriteLine(a.val);
            Console.Read();
        }
    }
}


The code will print 10.
All this does, is that it gives both 'a' and 'b' access to change the 'val' integer...
Tony




PostPosted: Thu Mar 24, 2011 8:02 pm   Post subject: RE:Saving a variable as a variable??

@z_cross_fire: "new" returns a pointer Smile
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: