Giving a single variable the value of two other variables?
Author |
Message |
m84uily
|
Posted: Thu Mar 12, 2009 5:14 pm Post subject: Giving a single variable the value of two other variables? |
|
|
code: |
var streamA, streamB, streamC, count : int
var numberA, numberB, numberC : array 1 .. 8 of int
var aA, bA, cA, dA, eA, fA, gA, hA, aB, bB, cB, dB, eB, fB, gB, hB, aC, bC, cC, dC, eC, fC, gC, hC : int
open : streamA, "C:\\A.txt", get
open : streamB, "C:\\B.txt", get
open : streamC, "C:\\C.txt", put
for i : 1 .. 8
get : streamA, numberA (i)
end for
for i : 1 .. 8
get : streamB, numberB (i)
end for
for i : 1 .. 8
numberC (i) := numberA (i) and numberB (i)
end for
for i : 1 .. 8
put numberC (i)
end for
|
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. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Insectoid

|
Posted: 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. |
|
|
|
|
 |
m84uily
|
Posted: 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:
code: |
for x : 1 .. 8
numberC (x) := numberA (x)
end for
for x : 8 .. 16
numberC (x) := numberB (x + 8)
end for
|
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. |
|
|
|
|
 |
Tony

|
Posted: 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 |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
m84uily
|
Posted: 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. |
|
|
|
|
 |
jbking
|
Posted: 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. |
|
|
|
|
 |
Tony

|
Posted: 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 |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
m84uily
|
Posted: 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. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Insectoid

|
Posted: 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. |
|
|
|
|
 |
|
|