hi!
i have listed the entire code for reference at the bottom.
however I have tried something similar to what you suggested
I am still having the trouble of the sorting 'jumping ahead'.
the problem part is
count :=1
begin
... values are entered
for i:=0 to count do begin
if CustomerSalary[i] > CustomerSalary[count] then begin
<arrays are sorted here>
tmpCustomerName:= CustomerName[i];
tmpCustomerLoan:= CustomerLoan[i];
tmpCustomerSalary:= CustomerSalary[i];
CustomerName[i]:= CustomerName[count];
CustomerLoan[i]:= CustomerLoan[count];
CustomerSalary[i]:= CustomerSalary[count];
CustomerName[count]:= tmpCustomerName;
CustomerLoan[count]:= tmpCustomerLoan;
CustomerSalary[count]:= tmpCustomerSalary;
end;
end;
count is incremented here
end.
Program ;
var CustomerName: array[1..25] of string;
var CustomerLoan: array[1..25] of integer;
var CustomerSalary: array[1..25] of integer;
var i,j: integer;
var tmpCustomerName:string;
var tmpCustomerLoan:integer;
var tmpCustomerSalary:integer;
var count: integer;
const array_size =25;
var YesOrNo: char;
Begin
count:=0;
FOR i:=0 TO 25 DO
begin
Writeln('Please enter Customer Name');
Readln(CustomerName[i]);
Writeln('Please enter ', CustomerName[i],' loan');
Readln(CustomerLoan[i]);
Writeln('Please enter ', CustomerName[i],' Salary');
Readln(CustomerSalary[i]);
Writeln('ALL CUSTOMERS');
FOR i:=0 TO count DO
begin
Writeln(CustomerName[i],'----Loan:',CustomerLoan[i],'-----Salary:',CustomerSalary[i]);
end;
Writeln('---------------------------------------------------');
Writeln('Customers with Loans equal to 1');
FOR i:=0 TO count DO
begin
if CustomerLoan[i]= 1 then begin
Writeln('Loan:',CustomerLoan[i],'---Name---',CustomerName[i],'-----Salary:',CustomerSalary[i]);
end;
end;
Writeln('---------------------------------------------------');
for i:=0 to count do begin
if CustomerSalary[i] > CustomerSalary[count] then begin
tmpCustomerName:= CustomerName[i];
tmpCustomerLoan:= CustomerLoan[i];
tmpCustomerSalary:= CustomerSalary[i];
CustomerName[i]:= CustomerName[count];
CustomerLoan[i]:= CustomerLoan[count];
CustomerSalary[i]:= CustomerSalary[count];
CustomerName[count]:= tmpCustomerName;
CustomerLoan[count]:= tmpCustomerLoan;
CustomerSalary[count]:= tmpCustomerSalary;
end;
end;
end;
Writeln('5 Customers with highest salaries');
FOR i:=0 TO 5 DO
begin
Writeln('Salary:',CustomerSalary[i],'---Name----',CustomerName[i],'----Loan:',CustomerLoan[i]);
end;
Writeln('---------------------------------------------------');
count :=count +1;
end;
end.