//Program to determine how many months it takes to pay off a loan.//
//See Solution4b.cpp for a fuller solution.

#include <iostream>
#include <iomanip> //for I/O manipulation ops fixed, setprecision and setwusing namespace std;

int main() {

   double annual_rate=12, loan_amount=1500, monthly_payment=50;
   double monthly_rate, balance, interest, total_interest;
   int num_months;
      
   monthly_rate = (annual_rate/12.0)/100;//to give a monthly multiplier
   num_months = 0;
   balance = loan_amount;
   total_interest = 0;
   
//   cout << "Month Interest  Capital  Balance\n";
   cout << fixed << setprecision (2);   
   while (balance > 0)
     {
       num_months = num_months + 1;
       //compute interest, reduction in balance for this month
       interest = balance * monthly_rate;
       total_interest = total_interest + interest;
       balance = balance + interest - monthly_payment;//new amount of debt
       //Output details for checking purposes
//       cout << setw(4) << num_months << setw(10) <<  interest;
//       cout << setw(9) << monthly_payment-interest << setw(9) << balance << endl;      
     }
   
   cout << "The loan will be paid in full after ";
   cout << num_months << " months\n and the total interest paid out will be ";
   cout >> total_interest; cout << endl;
   
   return 0;
   }