/* ********************************************
		Program: lab08tp.cpp
		
		Tonya M. Payne
		COSC 1435 :: Section 3
		
		Version: 1.0
		Date:		Original 10 March 2010
		Purpose:	Make an amortization table from user input and print
					it out into a user-friendly format
		
		Input: Keyboard
		Output: To screen


*///////////////////////////////////////////////

#include <iostream> //Used for cout
#include <iomanip>	//For output formatting
#include <cmath>  	//For math functions

using namespace std; //compiler environment

main()
{
	double	dLoanAmount,		//initial amount of the loan
			dIntRate,			//yearly interest rate
			dTerm,				//calculates the monthly interest
			dMonInterest = 0.,	//monthly interest, changes each month
			dMonPrincipal,		//monthly principal, changes each month
			dPayment,			//payment, changes each month
			dBalance,			//balance on the loan, changes each month
			dTotalInterest;		//total interest paid, changes each month
			
	int		iYears,				//number of years of the loan
			iMonths = 1;		//number of months of the loan
			
	
	//get initial data 
	cout << "What is the amount of money you are borrowing?" << endl;
	cin  >> dLoanAmount;
	cout << "What is your interest rate? (example: enter 5.5 for 5.5%)" << endl;
	cin  >> dIntRate;
	dIntRate = dIntRate * 100;
	cout << "How long is the loan for (in years)?" << endl;
	cin  >> iYears;
	
	dTerm = pow(( 1.0 + ( dIntRate/12.0 )), (12.0 * iYears) );
	cout << dTerm << endl;
	
	dBalance = dLoanAmount;
			
	while ( dBalance > 0.0 )
		{
		//prints out the number of months
		cout << " " << iMonths << " | ";
		
		//monthly interest
		dMonInterest = dTerm * dBalance;
		cout << dMonInterest << " | ";
		
		//monthly payment
		dPayment = (dLoanAmount * ( (dIntRate/12.0) * dTerm ))/( dTerm - 1.0 );
		cout << dPayment << " | ";
		
		//monthly principal 
		dMonPrincipal = dPayment - dMonInterest;
		cout << dMonPrincipal << " | ";
		
		//balance
		dBalance = dBalance - dMonPrincipal;
		cout << dBalance << " | ";
		
		//total interest
		dTotalInterest = dTotalInterest + dMonInterest;
		
		cout << endl;

		iMonths = iMonths + 1;
		}
		
	
	return 0;
}
