I know this must be a easy question, but for some reason I can not find the answer. I have a C++ Mortgage Calculator program and I just need to add a function to it. I want the user to have the ability to add a text file with data in it. Thank you
Here is the code:
#include <iostream>
#include <cmath>
#include <stdlib.h>
using namespace std;
int main()
{
double p;
double i;
int j;
int NumberOfPayments;
int MonthlyPymtCtr;
double m;
double LoanBalance;
double MonthlyIntPd;
double MonthlyPrinPd;
const char NL='\n';
const char TAB='\t';
char listmore;
int dividelist=0;
char quit;
quit = 'C';
while (quit != 'Q' && quit != 'q')
{
// loan data
cout << "\n Mortgage web program";
cout << "\n __________________________
____ ";
cout<<"\n\nEnter Mortgage Amount: $";
cin >> p;
cout<<"\n\nEnter Mortgage term in Years: ";
cin >> j;
cout<<"\n\nEnter the Interest Rate: ";
cin >> i;
// monthly payment calc
m = p * (i/1200)/(1-pow(1+(i/1200)
,-1*(j*12)
));
//output payment amount
cout<<"\nYour Monthly Payment is $"<<m<<".\n"<<endl;
//loan balance and interest paid calculation
NumberOfPayments = j * 12;
dividelist = 0;
for (MonthlyPymtCtr=1; MonthlyPymtCtr<=NumberOfPa
yments; ++MonthlyPymtCtr)
{
MonthlyIntPd = p * (i/1200);
MonthlyPrinPd = m - MonthlyIntPd;
LoanBalance = p - MonthlyPrinPd;
if (LoanBalance < 0)
LoanBalance = 0;
p = LoanBalance;
if (dividelist == 0)
{
//cout<<"Loan Balance and Interest Paid\n\n";
cout<<"Loan Balance"<<TAB<<"Interest Paid"<<NL;
cout<<"____________"<<TAB<
<"________
_____"<<NL
<<NL;
}
cout<<LoanBalance<<TAB<<TA
B<<Monthly
IntPd<<NL;
++dividelist;
if (dividelist==12)
{
cout<<"Enter 'C' to continue,"<<"'N' for new data,"
<<"'Q' to quit>";
cin>>listmore;
if ((listmore=='C')||(listmor
e=='c'))
dividelist=0;
else if ((listmore=='N')||(listmor
e=='n'))
break;
else if ((listmore=='Q')||(listmor
e=='q'))
return 0;
}
}
do
{
cout<<"Enter C to continue, Q to quit>";
cin>>quit;
cout<<'\n';
} while ((quit!='q')&&(quit!='Q')&
&(quit!='c
')&&(quit!
='C'));
}
//cout<<"Payment!\n";
return 0;
}