Arrays Part 5 - Parallel arrays

preview_player
Показать описание
Here we explain how to make use of parallel arrays: multiple arrays that have corresponding values in the same position in each array.

Arrays Video Series

#MrLongEducation #Programming #Arrays
Рекомендации по теме
Комментарии
Автор

0:10 now that right there was a violation 😆

labeebah
Автор

Hi, how would you use the selection sort for parallel arrays but alphabetically?

margosfeet
Автор

Hello Mr long, I am busy with a program where I need to display 3 arrays 1 about the book name, 1 about the amount of books ordered and the last about the price, I take the input from a spin edit for the amount of books and the books ID on the one form and then have to write it over to the other form I managed to do this but my display shows for example:
X-faktor 2 R300
and if that same book is ordered but only 1
X-faktor 1 R150
I would like to display these values as 1 for example
X-faktor 3 R450
BUT the user can also order a other book after X-faktor and then again X-faktor
If needed this is my current code witch does not work atm
public
{ Public declarations }
arrBook: array [1 .. 100] of string;
arrAmount: array [1 .. 100] of integer;
arrPrice: array [1 .. 100] of string;
SID: string;
itotal, i: integer;
bfound: boolean;
end;

var
formadd: Tformadd;

implementation

uses reserve_u;
{$R *.dfm}

procedure Tformadd.Button1Click(Sender: TObject);
var
iloop, k, i3: integer;
rsum: real;
arrfound: array [1 .. 100] of integer;
begin
bfound := false;




with DataModule4 do
begin
tblbook.First;
while not tblbook.Eof do
begin

if tblbook['BookID'] = SID then
begin
bfound := true;
arrBook[i] := tblbook['BookName'];
arrAmount[i] := Spin.Value;
for k := 1 to 100 do

begin
if arrBook[i] = arrbook[k] then

begin

if i > k then
begin
arramount[k] := arramount[k]+ arramount[i] ;
for I3 := 100 downto i do
begin
arrbook[I3] := arrbook[I3-1] ;
arramount[I3] := arramount[I3-1];

end; //for i3

end; // if i < k



end; //if arrBook[i] = arrbook[k]

end; //for k
arrPrice[i] := floattostr( arramount[i]* (tblbook['Price']));
itotal := itotal + strtoint(arrPrice[i]);


(arrBook[i] + #9 + inttostr(arrAmount[i]) + #9 + 'R' + arrPrice[i]);


inc(i);
Showmessage('Book successfully added')

end; //if Sid

tblbook.Next;
end;

end;


if bfound = false then
begin
Showmessage('Failed to add book');
end;
end;
Thank you so much !

lstguy