loan calculator problems

Feb 11, 2010 at 2:46am
i have the program pretty much complete but i am having problems with the output, it seems like the formulas are wrong. it is supposed to take user input of the amount of loan, APR, payments per year, and total number of payments and print a repayment schedule in a table and show the payment amount, amount interest, amount to principal, and balance after this payment in the table. under the table it is supposed to show total payment amount and total interest payment. here is my code.

# include <iostream>
# include <iomanip>
# include <cmath>

using namespace std;

int main ()
{
double loanAmountA;
double annualRate;
double paymentAmount;
double amountInterest;
double ratePeriod;
double balanceAfter;
double amountApplied;
double balance;
double paymentPeriod;
int paymentsPerYear;
int totalPayments;
int loanCount = 1;
int paymentCount = 1;
bool anotherLoan = true;
char response;

while (anotherLoan == true)
{
cout<<"Enter amount of loan A:$ ";
cin>>loanAmountA;
cout<<endl;
cout<<"Enter annual percentage rate (APR): "<<"%";
cin>>annualRate;
cout<<endl;
cout<<"Enter the number of payments per year: ";
cin>>paymentsPerYear;
cout<<endl;
cout<<"Enter the total number of payments: ";
cin>>totalPayments;
cout<<endl;
cout<<"Payment Payment Amount Amount to Balance after";
cout<<endl;
cout<<"Number Amount Interest Principal This Payment";
cout<<endl;



cin.ignore(80,'\n');


while (paymentCount <=totalPayments)
{
annualRate = annualRate / 100;
balance = loanAmountA - totalPayments * paymentAmount;
ratePeriod = balance * annualRate;
paymentAmount = loanAmountA * (totalPayments / paymentsPerYear * annualRate) / totalPayments;
balanceAfter = balance - paymentAmount;
balance = loanAmountA - (paymentCount * paymentAmount);


cout<<left<<setprecision(0)<<setw(3)<<paymentCount;
cout<<setw(13)<<left<<fixed<<setprecision(2)<<paymentAmount;
cout<<setw(26)<<left<<fixed<<setprecision(2)<<ratePeriod;
cout<<setw(39)<<left<<fixed<<setprecision(2)<<balance;
cout<<setw(42)<<left<<fixed<<setprecision(2)<<balanceAfter;





if (paymentCount % 12 == 0)
{
cout<<endl;
cout<<"Hit <Enter> to continue: "<<endl;
cin.ignore(80,'\n');
cin.get();
}
paymentCount++;
loanCount++;
cout<<endl;
}

cout<<"Would you like to calculate another loan? y/n and <enter>";
cin>>response;
if (response == 'n')
{
anotherLoan = false;
cout<<endl<<endl;
cout<<"There were"<<loanCount<< "loans processed.";
cout<<endl<<endl;
}
}
return 0;
}

Feb 11, 2010 at 2:57am
This belongs in a help forum, not the lounge.
Anyway, that needs code tags.
Feb 11, 2010 at 4:48pm
what do you mean code tags? what is that?
Feb 11, 2010 at 4:49pm
closed account (z05DSL3A)
Read: http://www.cplusplus.com/articles/firedraco1/
Feb 11, 2010 at 6:09pm
The reason you don't know what code tags are is because you should have read "Welcome! READ BEFORE POSTING" in the beginner's forum.
Topic archived. No new replies allowed.