Squirrelly
Programmer
I'm trying to add the interest column and the principal columns here is what I have so far:
// This program produces a loan amortization
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;
int main()
{
ofstream outfile("A:Mort.txt"
char name[31];
float loan, rate, years, balance, term, payment;
cout << "Enter the name of the mort. recipant. ";
cin.getline(name, 31);
cout << "Loan amount: $";
cin >> loan;
cout << "Annual Interest Rate: ";
cin >> rate;
cout << "Years of loan: ";
cin >> years;
term = pow((1 + rate / 12.0), 12.0 * years);
payment = (loan * rate / 12.0 * term) / (term - 1.0);
outfile.precision(2);
outfile.setf(ios::fixed | ios::showpoint | ios::left);
outfile << "The loan belongs to : " << name << endl;
outfile << "Monthly payment: $" << payment << endl;
outfile << endl;
outfile << setw(13) << "Pay. No.";
outfile << setw(13) << "Interest";
outfile << setw(13) << "Principal";
outfile << setw(13) << "Balance" << endl;
outfile << "----------------------------------------------\n";
balance = loan;
for (int month = 0; month < (12 * years); month++)
{
float minterest, principal;
minterest = rate / 12 * balance;
principal = payment - minterest;
outfile << setw(13) << (month + 1);
outfile << setw(13) << minterest;
outfile << setw(13) << principal;
outfile << setw(13) << balance << endl;
balance -= principal;
if (((month + 1) % 6) == 0)
{
outfile << endl;
}
if (((month + 1) % 36)==0)
{
outfile << setw(13) <<"SubTotal " << endl;
outfile << endl;
}
}
outfile.close();
return 0;
}
I want to add the 2 columns and display the total... CAn't figure out how to do it. Any help would be greatful...
TIA
Squirrelly
// This program produces a loan amortization
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;
int main()
{
ofstream outfile("A:Mort.txt"
char name[31];
float loan, rate, years, balance, term, payment;
cout << "Enter the name of the mort. recipant. ";
cin.getline(name, 31);
cout << "Loan amount: $";
cin >> loan;
cout << "Annual Interest Rate: ";
cin >> rate;
cout << "Years of loan: ";
cin >> years;
term = pow((1 + rate / 12.0), 12.0 * years);
payment = (loan * rate / 12.0 * term) / (term - 1.0);
outfile.precision(2);
outfile.setf(ios::fixed | ios::showpoint | ios::left);
outfile << "The loan belongs to : " << name << endl;
outfile << "Monthly payment: $" << payment << endl;
outfile << endl;
outfile << setw(13) << "Pay. No.";
outfile << setw(13) << "Interest";
outfile << setw(13) << "Principal";
outfile << setw(13) << "Balance" << endl;
outfile << "----------------------------------------------\n";
balance = loan;
for (int month = 0; month < (12 * years); month++)
{
float minterest, principal;
minterest = rate / 12 * balance;
principal = payment - minterest;
outfile << setw(13) << (month + 1);
outfile << setw(13) << minterest;
outfile << setw(13) << principal;
outfile << setw(13) << balance << endl;
balance -= principal;
if (((month + 1) % 6) == 0)
{
outfile << endl;
}
if (((month + 1) % 36)==0)
{
outfile << setw(13) <<"SubTotal " << endl;
outfile << endl;
}
}
outfile.close();
return 0;
}
I want to add the 2 columns and display the total... CAn't figure out how to do it. Any help would be greatful...
TIA
Squirrelly