View Full Version : Array Help,
I have a Array, full on Extended's.
I want to Take each one * by a number and add it to another array in the exact same position, I'm currently stumped atmo.
Thanks
Mat
x[Warrior]x3500
07-09-2012, 08:09 PM
program new;
var
arrayOne, arrayTwo: array of Extended;
i: integer;
begin
arrayOne:= [1,2,3,4,5,6,7];
arrayTwo:= [7,6,5,4,3,2,1];
for i:=0 to high(arrayOne)do
begin
arrayOne[i]:= arrayOne[i]*{insert num here};
end;
for i:=0 to high(arrayOne)do
begin
arrayTwo[i]:= arrayOne[i]+arrayTwo[i];
end;
end.
Nebula
07-09-2012, 08:11 PM
Try Something like this... not sure if it will work though.
Procedure mat;
var
StartArray, EndArray: TVariantArray;
begin
SetLength(EndArray, StartArray);
For i := 0 to high(StartArray) do
EndArray[i] := (StartArray[i] * ###);
end;
Runaway
07-09-2012, 08:34 PM
Try Something like this... not sure if it will work though.
Procedure mat;
var
StartArray, EndArray: TVariantArray;
begin
SetLength(EndArray, StartArray);
For i := 0 to high(StartArray) do
EndArray[i] := (StartArray[i] * ###);
end;
It will work if you do this:
Procedure mat;
var
StartArray, EndArray: TVariantArray;
i: Integer; // <- dat guy
begin
SetLength(EndArray, Length(StartArray)); // <- length too :P
For i := 0 to high(StartArray) do
EndArray[i] := (StartArray[i] * ###);
end;
Not entirely sure what you're trying to do, but replacing it's own values works just fine :o
Procedure MultiplyArray(Num: Extended);
var
Arr: TExtendedArray;
i: Integer;
begin
For i := 0 to High(Arr) do
Arr[i] := Arr[i] * Num;
end;
Get a little fancy, maybe?
Procedure MultiplyArray(Num: TExtendedArray);
var
Arr: TExtendedArray;
i: Integer;
begin
For i := 0 to High(Arr) do
Arr[i] := Arr[i] * Num[i];
end;
How about a few specific values?
Procedure MultiplyArray(Num: Extended; Which: TExtendedArray);
var
Arr: TExtendedArray;
i, ii: Integer;
begin
For i := 0 to High(Arr) do
begin
For ii := 0 to High(Which) do
begin
if (Arr[i] = Which[ii]) then
Arr[i] := Arr[i] * Num;
end;
end;
end;
/bored
Lol, Thanks for neg rep I totally forgot about this I was to busy in code.
Justin
07-15-2012, 11:46 AM
Wow, someone neg repped you for that? What has Villavu come to??
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.