home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
ENTERPRS
/
CPM
/
UTILS
/
A
/
AMORTIZE.LBR
/
AMORTIZE.PZS
/
AMORTIZE.PAS
Wrap
Pascal/Delphi Source File
|
2000-06-30
|
3KB
|
152 lines
program AMORTIZE;
{see amortcpm.doc}
const COLUMN_POSITION = 56;
ROW_OFFSET = 9;
var INPUT : array[1..4] of string[10];
FIELD : integer;
RESPONSE : char;
COLUMN : integer;
ACTIVE : Boolean;
RESET_MESSAGE : Boolean;
AMOUNT : real;
MONTHS : integer;
RATE : real;
PAYMENT : real;
{$IAMORT1.INC}
{$IAMORT2.INC}
procedure Compute_Amount;
var HOLD : real;
begin
HOLD := POWER(1.0 + (RATE / 1200.0),MONTHS);
AMOUNT := (PAYMENT * (HOLD - 1.0)) / ((RATE / 1200.0) * HOLD);
HOLD := frac(AMOUNT*100.0);
AMOUNT := ((AMOUNT*100.0)-HOLD)/100.0;
end;
procedure Compute_Months;
var M_RATE, PRINCIPAL : real;
begin
M_RATE := RATE / 1200;
PRINCIPAL := AMOUNT;
MONTHS := 0;
while PRINCIPAL > 0.0 do begin
PRINCIPAL := PRINCIPAL - (PAYMENT - PRINCIPAL * M_RATE);
MONTHS := MONTHS + 1;
end;
end;
procedure Compute_Rate;
var HOLD_1, HOLD_2, HOLD_1_PART, HOLD_2_PART : real;
begin
RATE := 1200.0 * PAYMENT / AMOUNT - 0.01;
repeat
RATE := RATE + 0.001;
HOLD_1_PART := POWER(1.0 + RATE / 1200.0, MONTHS);
HOLD_2_PART := POWER(1.0 + (RATE + 0.001) / 1200.0, MONTHS);
HOLD_1 := RATE / 1200.0 * AMOUNT * HOLD_1_PART /
(HOLD_1_PART - 1.0);
HOLD_2 := (RATE + 0.001) / 1200.0 * AMOUNT * HOLD_2_PART /
(HOLD_2_PART - 1.0);
if (HOLD_1 > PAYMENT) and (HOLD_2 > PAYMENT) then
RATE := RATE - 0.1;
until (PAYMENT > HOLD_1) and (PAYMENT < HOLD_2);
RATE := RATE+0.005;
HOLD_1 := frac(RATE*100.0);
RATE := ((RATE*100.0)-HOLD_1)/100.0;
end;
procedure Compute_Payment;
var HOLD : real;
begin
HOLD := Power(1.0 + RATE / 1200.0, MONTHS);
PAYMENT := ((RATE / 1200.0) * HOLD * AMOUNT) / (HOLD - 1.0);
PAYMENT := PAYMENT+0.005;
HOLD := frac(PAYMENT*100.0);
PAYMENT := ((PAYMENT*100.0)-HOLD)/100.0;
end;
procedure Do_Amortization;
begin
if (AMOUNT <= 0.0) and (MONTHS > 0) and
(RATE > 0.0) and (PAYMENT > 0.0) then begin
Compute_Amount;
gotoxy(COLUMN_POSITION-12,ROW_OFFSET+1);
write(AMOUNT:9:2,' ');
Display_Amortization;
end
else
if (AMOUNT > 0.0) and (MONTHS <= 0) and
(RATE > 0.0) and (PAYMENT > 0.0) then begin
Compute_Months;
gotoxy(COLUMN_POSITION-12,ROW_OFFSET+2);
write(MONTHS:9,' ');
Display_Amortization;
end
else
if (AMOUNT > 0.0) and (MONTHS > 0) and
(RATE <= 0.0) and (PAYMENT > 0.0) then begin
Compute_Rate;
gotoxy(COLUMN_POSITION-12,ROW_OFFSET+3);
write(RATE:9:2,' ');
Display_Amortization;
end
else
if (AMOUNT > 0.0) and (MONTHS > 0) and (RATE > 0.0) then begin
Compute_Payment;
gotoxy(COLUMN_POSITION-12,ROW_OFFSET+4);
write(PAYMENT:9:2,' ');
Display_Amortization;
end
else begin
gotoxy(6,23);
write('You must define values > 0 for at least three fields. ');
RESET_MESSAGE := true;
end;
end;
{$IAMORT3.INC}
begin { main procedure }
AMOUNT := 0.0;
MONTHS := 0;
RATE := 0.0;
PAYMENT := 0.0;
Draw_Screen;
for FIELD := 1 to 4 do begin
INPUT[FIELD] := '0';
ACTIVE := true;
Set_Field;
end;
FIELD := 1;
New_Position;
Process_Input;
clrscr;
end.