{ Created by   Charles J. Arnett         }
{              111 Worman Dr.            }
{              Union   OH  45322         }
{              1-513-836-3272            }
{ Version 1.00 June 29, 1985             }
{ Version 2.00 July  4, 1985             }

{ Rev. 2 is adding months to duration of Loan. }
{  You can now figure loan for fractional part of years }

        { This program is used to calculate }
        { Money accounts. ie. IRA's, Savings, or Loan payments }

PROGRAM Money;

VAR Answer,Kind,Kind1,Enuf     : CHAR;
VAR S,L,P,D,Q,G,C              : CHAR;

VAR BalloonPayment,
    FinalAmount,
    InitialAmount,
    AnnualInterestRate,
    MonthlyAmount,
    F,R,H,W,X,Z,U    : REAL;

VAR I,
    Y,
    VerseCount,
    YearsOfAccount,
    AA,
    BB,
    CC,
    DD,
    EE          : INTEGER;

VAR J,
    K,
    A1,
    B1,
    C1,
    D1,
    K1,
    J1,
    I1   : STRING[10];

Procedure ClearScreen;
Begin
  GOTOXY(20,20);
  FOR BB := 1 TO 30 DO
    WRITELN;   { This will clear any screen }
  gotoXY(1,1);
End;

Procedure DrawBox;
Begin
  FOR AA := 1 TO 70 DO
    BEGIN
      gotoXY(AA,1);
      WRITELN('$');
    END;
  FOR AA := 1 TO 70 DO
    BEGIN
      gotoXY(AA,21);
      WRITELN('$');
    END;
  FOR AA := 1 TO 20 DO
    BEGIN
      GOTOXY(1,AA);
      WRITELN('$');
    END;
  FOR AA := 1 TO 20 DO
    BEGIN
      GOTOXY(70,AA);
      WRITELN('$');
    END;
End; { End Draw Box }

Procedure PrintSavings;
begin  { Begin routine to print savings }
    STR(InitialAmount:6:2,A1);
    STR(AnnualInterestRate:6:2,B1);
    STR(MonthlyAmount:6:2,D1);

    WRITELN(Lst,Chr(09),' INITIAL INVESTMENT?   = $',A1);
    WRITELN(Lst,Chr(09),' ANNUAL INTEREST RATE? =  ',B1,' %');
    WRITELN(Lst,Chr(09),' YEARS OF INVESTMENT?  =  ',YearsOfAccount);
    WRITELN(Lst,Chr(09),' MONTHLY INVESTMENT?   = $',D1);
    WRITELN(Lst,Chr(09),'');
    WRITELN(Lst,'');
    WRITELN(Lst,Chr(09),'$',J,'  THIS IS THE FINAL BALANCE');
    WRITELN(Lst,'');
    WRITELN(Lst,'');

end;  { End routine to Print Savings routine  }

Procedure PrintLoan;
begin  { Print Loan Summery }
    STR(InitialAmount:6:2,A1);
    STR(AnnualInterestRate:6:2,B1);
    STR(BalloonPayment:6:2,D1);

    WRITELN(Lst,Chr(09), '  INITIAL VALUE OF THE LOAN  = $',A1);
    WRITELN(Lst,Chr(09), '  ANNUAL INTEREST RATE       = ',B1,'%    ');
    WRITELN(Lst,Chr(09), '  LENGTH OF LOAN             = ',YearsOfAccount,' Years');
    WRITELN(Lst,Chr(09), '                               ',EE,' Months');
    WRITELN(Lst,Chr(09), '  FINAL BALLOON PAYMENT      = $',D1);
    WRITELN(LST,'');
    WRITELN(LST,'');
    STR(MonthlyAmount:4:2,K);
    STR(FinalAmount:4:2,J);
    WRITELN(Lst,Chr(09),'$',K,' THIS IS THE PAYMENT OF EACH MONTH');
    WRITELN(LST,'');
    WRITELN(LST,'');
    WRITELN(LST,Chr(09),'$',J,' THIS IS THE FINAL PAYMENT');
    WRITELN(LST,'');
    WRITELN(LST,'');

end; { End routine to Print Loan summery }


PROCEDURE Savings;
BEGIN { Ira or savings account }
  ClearScreen;
  DrawBox;
  GOTOXY(4,3);
  WRITELN(' INITIAL INVESTMENT?  = $___');
  GOTOXY(4,4);
  WRITELN(' ANNUAL INTEREST RATE? = ___ %');
  GOTOXY(4,5);
  WRITELN(' YEARS OF INVESTMENT? =  __');
  GOTOXY(4,6);
  WRITELN(' MONTHLY INVESTMENT?  = $___');
  GOTOXY(29,3);
  READLN(InitialAmount);
  GOTOXY(29,4);
  READLN(AnnualInterestRate);
  GOTOXY(29,5);
  READLN(YearsOfAccount);
  GOTOXY(29,6);
  READLN(MonthlyAmount);
  X := AnnualInterestRate/1200;  { Monthly Interest }
  Y := YearsOfAccount*12;    { Number of months }
  Z := 1;
  FOR I := 1 to Y DO  { Total Interest }
  Z  := Z * (1 + X);
  H := MonthlyAmount*(1+X)*((Z-1)/X); { Growth of monthly investment }
  R := InitialAmount*Z;  { Growth of initial investment }
  FinalAmount := H+R;  { Total growth }
  STR(FinalAmount:6:2,J);
  GOTOXY(20,10);
  if DD = 0 THEN
  BEGIN
    WRITELN ('$',J,'  THIS IS THE FINAL BALANCE');
    GOTOXY(5,18);
    WRITELN('  Do you want a hard copy?  Y/N');
    GOTOXY(45,18);
    READ(KBD,Answer);
    If UpCase(Answer) = 'Y' then PrintSavings;
  End; { end regular savings account }
  if DD = 1 THEN  {Display yearly Growth of Saavings }
  BEGIN
    ClearScreen;
    GOTOXY(1,1);
    FOR I := 1 to YearsOfAccount DO  { Total Interest }
    begin
      FOR CC := 1 to 12 do
      BEGIN
        H := MonthlyAmount*(1 + X); { Growth of monthly investment }
        R := InitialAmount*(1 + X);  { Growth of initial investment }
        FinalAmount := H+R;  { Total growth }
        InitialAmount := FinalAmount;
      END;
      STR(FinalAmount:6:2,J);
      WRITELN ('$',J:9,'  Balance at end of year ',I);
      IF (DD = 20) OR (I  = YearsOfAccount ) THEN
      BEGIN
        DD := 1;
        WRITELN(' Press any key to continue');
        READ(KBD,ANSWER);
        ClearScreen;
      END;
      DD := DD + 1;
    End;
    DD := 8;
  End; { end of display yearly growth }
  if DD = 2 THEN  { Print yearly Growth of Saavings }
  BEGIN
    WriteLn;
    WriteLn;
    WriteLn;
    PrintSavings;
    WriteLn(Lst,Chr(12));
    FOR I := 1 to YearsOfAccount DO  { Total Interest }
    begin
      FOR CC := 1 to 12 do
      BEGIN
        H := MonthlyAmount*(1 + X); { Growth of monthly investment }
        R := InitialAmount*(1 + x);  { Growth of initial investment }
        FinalAmount := H+R;  { Total growth }
        InitialAmount := FinalAmount;
      END;
      STR(FinalAmount:6:2,J);
      WRITELN (LST,CHR(09),'$',J:9,'  Balance at end of year ',I);
      IF DD = 61 THEN
      BEGIN
        DD := 1;
        WRITELN(Lst,Chr(12));
      END;
      DD := DD + 1;
    End; { Print list of growth }
  END;
DD := 8;
END; { End savings routine }


PROCEDURE Loan;
BEGIN
  ClearScreen;
  DrawBox;
  GOTOXY(3,3);
  WRITELN( '  INITIAL VALUE OF THE LOAN  = $____     ');
  GOTOXY(3,4);
  WRITELN( '  ANNUAL INTEREST RATE       =  ____%    ');
  GOTOXY(3,5);
  WRITELN( '  LENGTH OF LOAN             =  ___ Years ');
  GOTOXY(3,6);
  WRITELN( '                              & ___ Months');
  GOTOXY(3,7);
  WRITELN( '  FINAL BALLOON PAYMENT      = $___    ');
  gotoxy(35,3);
  READLN(InitialAmount);
  gotoxy(35,4);
  READLN(AnnualInterestRate);
  gotoxy(35,5);
  READLN(YearsOfAccount);
  gotoxy(35,6);
  READLN(EE);
  gotoxy(35,7);
  READLN(BalloonPayment);
  X := AnnualInterestRate/1200;  { Monthly Interest }
  Y := (YearsOfAccount*12) + EE; { Number of months }
  Z := 1;
  FOR I := 1 to Y DO { Total Interest }
    Z  := Z * (1 + X);
  W := 1/Z; { Reciprocal of Interest }
  H := InitialAmount-(BalloonPayment*W);
        { Initial loan minus effective value of ballon payment }
  R := (1-W)/X;
  MonthlyAmount := H/R; { Monthly payments }
  FinalAmount := (H/R) + BalloonPayment;
                 { Monthly payment plus final ballon payment }
  if DD = 1 then  { Dispay Amortization chart }
  begin
    ClearScreen;
    Writeln('Payment # | Payment | Principal | Interest | Balance');
    U := InitialAmount;
    for CC := 1 to Y do
      begin
        W := MonthlyAmount - (U*X); { Principal }
        U := InitialAmount - W; { New Balance }
        InitialAmount := U;
        FinalAmount := MonthlyAmount - W; { Interest }
        STR(MonthlyAmount:4:2,K);
        STR(W:4:2,J);
        STR(FinalAmount:4:2,K1);
        STR(U:4:2,J1);
        Writeln('# ',CC:3,'      $',K:7,'  $',J:7,'    $',K1:7,'   $',J1:9);
        IF (DD = 20) OR (CC = Y ) THEN
        BEGIN
          DD := 1;
          WRITELN(' Press any key to continue');
          READ(KBD,ANSWER);
          ClearScreen;
          Writeln('Payment # | Payment | Principal | Interest | Balance');
        END;
        DD := DD + 1;
      End;
  DD := 8;
  End;
  { Print out amortization chart }
  if DD = 2 then
  begin
    PrintLoan;
    WriteLn(Lst,Chr(12));
    STR(AnnualInterestRate:2:2,I1);
    Writeln(Lst,Chr(09),'Payment # | Payment | Principal | Interest  | Balance');
    U := InitialAmount;
    for CC := 1 to Y do
      begin
        W := MonthlyAmount - (U*X); { Principal }
        U := InitialAmount - W; { New Balance }
        InitialAmount := U;
        FinalAmount := MonthlyAmount - W; { Interest }
        STR(MonthlyAmount:4:2,K);
        STR(W:4:2,J);
        STR(FinalAmount:4:2,K1);
        STR(U:4:2,J1);
        Writeln(Lst,Chr(09),'# ',CC:3,'      $',K:7,'  $',J:7,'    $',K1:7,'   $',J1:9);
        IF CC = Y THEN WRITELN(Lst,Chr(12));
        IF DD = 61 THEN
        BEGIN
          DD := 1;
          WRITELN(Lst,Chr(12));
          Writeln(Lst,Chr(09),'Payment # | Payment | Principal | Interest  | Balance');
        END;
        DD := DD + 1;
      End;
  DD := 8;
  End; { End Hard copy of amortization }
  If DD = 0 then
    Begin
      STR(MonthlyAmount:4:2,K);
      STR(FinalAmount:4:2,J);
      gotoxy(15,10);
      WRITELN('$',K,' THIS IS THE PAYMENT OF EACH MONTH');
      gotoxy(15,12);
      WRITELN('$',J,' THIS IS THE FINAL PAYMENT');
      GOTOXY(5,18);
      WRITELN('  Do you want a hard copy?  Y/N');
      GOTOXY(45,18);
      READ(KBD,Answer);
      If UpCase(Answer) = 'Y' then PrintLOAN;
    End;
  DD := 8;
  End;

Procedure RomansRoad;
Begin
  VerseCount := VerseCount + 1;
  Case VerseCount of
   1 : begin
         WriteLn(' "... There is none righteous, no, not one." ');
         WriteLn('                                  Rom. 3:10');
       end;
   2 : begin
         WriteLn(' "For all have sinned, and come short of the ');
         WriteLn('  glory of God."                   Rom. 3:23');
       end;
   3 : begin
         WriteLn(' "For the wages of sin is death; but the gift');
         WriteLn('  of God is eternal life through Jesus Christ ');
         WriteLn('  our Lord."                        Rom. 6:23');
       end;
   4 : begin
         WriteLn(' "That if thou shalt confess with thy mouth');
         WriteLn('  the Lord Jesus, and shalt believe in thine ');
         WriteLn('  heart that God hath raised him from the ');
         WriteLn('  dead, thou shalt be saved."     Rom. 10:9');
       end;
  end;
  if VerseCount = 4 then VerseCount := 0;
end;

Begin { start main routine }
ClearScreen;
WRITELN(' This program written by Charles J. Arnett');
WRITELN(' of Union, Ohio  Phone No.  513-836-3272  ');
WRITELN(' Please call if you have any questions    ');
writeln('       or comments           ');
WriteLn;
DD := 8;
VerseCount := 0;
WriteLn('Type M for Menu');
READ(KBD,Kind);
REPEAT
  IF DD = 8 THEN ClearScreen;
  DD := 0;
  gotoXY(2,5);
  RomansRoad;
  gotoXY(3,09);
  WRITELN(' Type S to Run the Savings  program ');
  gotoXY(3,11);
  WRITELN(' Type G to show the Growth of the savings program');
  gotoXY(3,13);
  WRITELN(' Type C for hard Copy of the Growth of the savings program');
  gotoXY(3,15);
  WRITELN(' Type L to Run the Loan  program ');
  gotoXY(3,17);
  WRITELN(' Type P For Hard copy of Loan Amortization ');
  gotoXY(3,19);
  WRITELN(' Type D For Display of Loan Amortization  ');
  gotoXY(3,21);
  WRITELN(' Type Q to quit program ');
  READ(KBD,Kind);
  Kind1 := UpCase(Kind);
  Case Kind1 of
    'P' : Begin
            DD := 2;
            Loan;
          End;
    'D' : Begin
            DD := 1;
            Loan;
          End;
    'C' : Begin
            DD := 2;
            Savings;
          End;
    'G' : Begin
            DD := 1;
            Savings;
          End;
    'S' : Savings;
    'L' : Loan;
    'M' : DD := 8;
  End;
UNTIL Kind1 = 'Q';
GOTOXY(1,23)
END.
