Computer Science Canada Giving a single variable the value of two other variables? |
Author: | m84uily [ Thu Mar 12, 2009 5:14 pm ] | ||
Post subject: | Giving a single variable the value of two other variables? | ||
What I'm attempting to do with this code is give numberC(i) the values of numberA(i) and numberB(i). So, assuming numberA(i) has values: 1, 2, 3 and numberB(i) has values: 4, 5, 6 What I would want numberC(i) to be like would be: 1, 2, 3, 4, 5, 6 Could anyone give me some ideas? Help is much appreciated. |
Author: | Insectoid [ Thu Mar 12, 2009 5:19 pm ] |
Post subject: | RE:Giving a single variable the value of two other variables? |
Clever use of 2 for loops should do it. for x: 1..length (numberA) %fill in numberC's variables with numberA's end for for x : length (numberA)..length (numberB+numberA) numberC (x) := numberB (x + length (numberA) end for Now, I only posted code because I couldn't think of a way to explain it. If a mod deems it worthy of removal, go ahead. |
Author: | m84uily [ Thu Mar 12, 2009 5:27 pm ] | ||
Post subject: | Re: RE:Giving a single variable the value of two other variables? | ||
insectoid @ Thu Mar 12, 2009 5:19 pm wrote: Clever use of 2 for loops should do it.
for x: 1..length (numberA) %fill in numberC's variables with numberA's end for for x : length (numberA)..length (numberB+numberA) numberC (x) := numberB (x + length (numberA) end for Now, I only posted code because I couldn't think of a way to explain it. If a mod deems it worthy of removal, go ahead. Thanks! I find I am unable to use "length (numberA)" due to the error "Argument is the wrong type" by "length (numberA)" did you intend for me to replace that with "8" ? Well I assumed so, and changed the values to 8 my code now looks like this:
And will not run due to the error "Array subscript is out of range" which occurs on the line "numberC (x) := numberB (x + 8)" Hm, a little more help, or perhaps a bit of an explanation? Thanks in advance. |
Author: | Tony [ Thu Mar 12, 2009 5:51 pm ] |
Post subject: | RE:Giving a single variable the value of two other variables? |
numberC(i) is declared to be an int 1, 2, 3, 4, 5, 6 is not an int |
Author: | m84uily [ Thu Mar 12, 2009 5:57 pm ] |
Post subject: | Re: RE:Giving a single variable the value of two other variables? |
Tony @ Thu Mar 12, 2009 5:51 pm wrote: numberC(i) is declared to be an int
1, 2, 3, 4, 5, 6 is not an int Oh! What is it? But if it's the comas you're referring to, then that's my fault, the values should really be 1 2 3 and 4 5 6 which combine to make 1 2 3 4 5 6. |
Author: | jbking [ Thu Mar 12, 2009 6:05 pm ] |
Post subject: | RE:Giving a single variable the value of two other variables? |
I think you're not accounting for the length of one of the arrays. To take your example of A being {1,2,3} and B being {4,5,6} how is C supposed to only have 3 values? If you want to store {1,2,3,4,5,6} that is 6 values, not 3. I think I'd define C to be the length of A + length of B, which I'll leave you to figure out how to set that. |
Author: | Tony [ Thu Mar 12, 2009 6:07 pm ] |
Post subject: | RE:Giving a single variable the value of two other variables? |
I think the use of the term "number" in your code is misleading. If you mean something like "a b c" concatenated with "1 2 3" to make "a b c 1 2 3", then you are dealing with strings. Which is also not an int |
Author: | m84uily [ Thu Mar 12, 2009 6:34 pm ] |
Post subject: | Re: RE:Giving a single variable the value of two other variables? |
Tony @ Thu Mar 12, 2009 6:07 pm wrote: I think the use of the term "number" in your code is misleading. If you mean something like "a b c" concatenated with "1 2 3" to make "a b c 1 2 3", then you are dealing with strings. Which is also not an int
I'll do a search for "concatenated" thanks. |
Author: | Insectoid [ Thu Mar 12, 2009 7:41 pm ] |
Post subject: | RE:Giving a single variable the value of two other variables? |
Concatenation is just joining 2 or more strings together. |