/////////////////////////////////////////////////////////
// paym: a monthly payment calculator                  //
//                                                     //
// Author: Rami Kuttaineh                              //
//         rami.kuttaineh at gmail.com                 //
//                                                     //
// GIVEN: The term, rate of interest, and loan amount; //
//        This outputs your monthly mortgage payment.  //
/////////////////////////////////////////////////////////

#include <iostream>
#include <cstdlib>
#include <cmath>

#define term double
#define rate double
#define loan double
#define monthly double

int main(int argc, char *argv[]) 
{
  if (argc > 1)
  {
      term n = strtod(argv[1], NULL) * 12;        // number of months
      rate r = strtod(argv[2], NULL) / 100 / 12;  // monthly interest rate
      loan a = strtod(argv[3], NULL);             // loan ammount

      monthly MP = (a * ( r * pow( (1 + r),n ) )) / ((pow( (1 + r),n )) - 1);

      std::cout << MP << std::endl;		  // output monthly payment

      system("PAUSE");  // inserted to allow execution from Start > Run:
      return 0;
  } else 
    {
        std::cout << "usage: paym term rate principle" << std::endl;
        system("PAUSE");
    }
}