/* problem 5 - a loan program

   Programmer: R. ALbright
   Course:     CIS 105
   Date:       9/1/2005

   Include the needed libraries - math.h is needed because we are using 
   the pow math function.*/

#include<stdio.h>
#include<math.h>

int main(void) {
   /* Set up the data area: */
   double amount, percent, periodic;
   double term, payment;
   double totint;
   int months;

   /* Interactive section: request and scan in the amount
      of the loan, the annual rate of interest, and the duration.*/
   printf("Enter the amount of the loan: ");
   scanf("%lf", &amount);
   printf("Now, enter the annual interest rate(%%): ");
   scanf("%lf", &percent );
   printf("and the number of months for the loan: ");
   scanf("%d", &months);

   /* computations:  convert to periodic rate, compute pow for
      efficiency, then compute the periodic payment. */
   periodic = percent/100/12;
   term = pow( 1+periodic, months);
   payment = amount*term/(term-1)*periodic;
   totint = payment*months - amount;

   /* and display results - in a nice tabular format: */
   printf("\n\n\n\tLoan Manager Output\n");
   printf("\t-------------------\n");
   printf("Inputs:\tloan amount:\t\t%6.2f\n", amount);
   printf("\tannual interest rate\t%6.2f\n", percent);
   printf("\tnumber of periods:\t%3d\n", months);
   printf("\nOutputs: monthly payment:\t%7.2f\n", payment);
   printf("\t total interest: \t%7.2f\n", totint);

   /* return to the shell: */
   return 0;
}
