Hello,
I really need some help on this program (load calculation) I have been working on but unfortunately my calculations don't work out correctly. I don't where am I going wrong. Code is on the bottom.
I enter the following data. Amount of load = 1500.00, Annual percentage rate = 14.0, and How many months to pay back the loan = 12.
The first line should output Payment Number = 1, Interest Paid = 17.50, Principal Paid = 117.18, Cumulative Interest = 17.50, Total Paid to Date = 134.68, New Balance Due = 1382.82. And the last line should be Payment Number = 12, Interest Paid = 1.55, Principal Paid = 133.13, Cumulative Interest = 116.17, Total Paid to Date = 1616.17, New Balance Due = 0.00.
Thank you for your help.
Yuna
Code:
#include <iostream> //for cout and cin
#include <conio.h> //for getch
#include <cmath>
#include <iomanip>
using namespace std;
void Getdata(double& Amount, double& Percent, int& Months);
void Caldata(double& Amount, double& Percent, int& Months,
double& InterestPaid, double& PrincipalPaid, double& CumlInterest, double& TotalPaidDate, double& MonthlyPayment, double& NewBalance, int& PaymentNum);
void Displaydata(double& Amount, double& Percent, int& Months, double& InterestPaid, double& PrincipalPaid, double& CumlInterest, double& TotalPaidDate, double& MonthlyPayment, double& NewBalance, int& PaymentNum);
void Displayheader(double& Amount, double& Percent, int& Months, double& MonthlyPayment);
void setvar(double& CumlInterest, double& TotalPaidDate, double& InterestPaid, int& PaymentNum, double& NewBalance, double& Amount);
void GetResponse(char& response);
int main()
{
double Amount;
double Percent;
double InterestPaid;
double PrincipalPaid;
double CumlInterest;
double TotalPaidDate;
double MonthlyPayment;
double NewBalance;
int PaymentNum;
int Months;
char response;
Getdata(Amount, Percent, Months);
Displayheader(Amount, Percent, Months, MonthlyPayment);
setvar(CumlInterest, TotalPaidDate, InterestPaid, PaymentNum, NewBalance, Amount);
do
{
Caldata(Amount, Percent, Months, InterestPaid, PrincipalPaid, CumlInterest, TotalPaidDate, MonthlyPayment, NewBalance, PaymentNum);
Displaydata(Amount, Percent, Months, InterestPaid, PrincipalPaid,
CumlInterest, TotalPaidDate, MonthlyPayment, NewBalance,
PaymentNum);
}while (PaymentNum <= Months);
GetResponse( response);
getch();
return 0;
}
void Getdata(double& Amount, double& Percent, int& Months)
{
cout << "What is the amount of the loan? ";
cin >> Amount;
cout << "What is the annual percentage rate? ";
cin >> Percent;
cout << "How many months will you take to pay back the loan? ";
cin >> Months;
while ((Percent < 1.0) || (Percent > 20.0))
{
cout << Percent << "%" << " is not a vaild interest rate.\n";
cout << "Try again. Please enter interest rate between 1% and 20% ";
cin >> Percent;
}
cout << endl;
}
void Caldata(double& Amount, double& Percent, int& Months,
double& InterestPaid, double& PrincipalPaid,
double& CumlInterest, double& TotalPaidDate,
double& MonthlyPayment, double& NewBalance, int& PaymentNum)
{
MonthlyPayment = Amount * (Percent/1200)/(1.0 - pow((1.0 + (Percent/1200)), -Months));
InterestPaid = ((Percent/100) / Months) * Amount;
CumlInterest = CumlInterest + InterestPaid;
PrincipalPaid = MonthlyPayment - InterestPaid;
TotalPaidDate = TotalPaidDate + MonthlyPayment;
NewBalance = NewBalance - PrincipalPaid ;
PaymentNum++;
Months--;
}
void Displayheader(double& Amount, double& Percent, int& Months, double& MonthlyPayment)
{
MonthlyPayment = Amount * (Percent/1200)/(1.0 - pow((1.0 + (Percent/1200)), -Months));
cout << fixed << showpoint;
cout << setw(55) << "Loan Amortization" << endl << endl;
cout << setw(15) << "Amount" << setw(25) << "Annual % Interest" << setw(15) << "Months" << setw(25) << "Monthly Payment" << endl;
cout << setprecision(2) << setw(15) << Amount << setw(18) << setprecision(2) << Percent << setw(20) << Months << setw(27) << setprecision(2) << MonthlyPayment << endl;
cout << endl << endl;
cout << "Payment" << setw(12) << "Interest" << setw(16) << "Principal" << setw(20) << "Cumlative" << setw(20) << "Total Paid" << setw(20) << "New Balance" << endl;
cout << "Number" << setw(11) << "Paid" << setw(15) << "Paid" << setw(23) << "Interest" << setw(18) << "to Date" << setw(18) << "Due" << endl << endl;
cout << "--------------------------------------------------------------------------------------------------" << endl;
}
void Displaydata(double& Amount, double& Percent, int& Months, double& InterestPaid, double& PrincipalPaid,
double& CumlInterest, double& TotalPaidDate,
double& MonthlyPayment, double& NewBalance, int& PaymentNum)
{
cout << fixed << showpoint;
cout << setw(3) << PaymentNum << setw(14) << InterestPaid << setw(17) << PrincipalPaid << setw(20) << CumlInterest << setw(20) << TotalPaidDate << setw(20) << NewBalance << endl;
}
void setvar(double& CumlInterest, double& TotalPaidDate, double& InterestPaid, int& PaymentNum, double& NewBalance, double& Amount)
{
CumlInterest = 0.0;
TotalPaidDate = 0.0;
InterestPaid = 0.0;
PaymentNum = 0;
NewBalance = Amount;
}
//do
// {
void GetResponse(char& response)
{
cout << "Do you want to continue? Y or N: " << endl;
cin >> response;
cout << endl << endl;
while (response != 'Y' && response != 'y' && response != 'N' && response != 'n')
{
cout << "You did not enter valid response. Please enter Y or N";
cin >> response;
}
}
//}while(response == 'Y' || response == 'y');
I really need some help on this program (load calculation) I have been working on but unfortunately my calculations don't work out correctly. I don't where am I going wrong. Code is on the bottom.
I enter the following data. Amount of load = 1500.00, Annual percentage rate = 14.0, and How many months to pay back the loan = 12.
The first line should output Payment Number = 1, Interest Paid = 17.50, Principal Paid = 117.18, Cumulative Interest = 17.50, Total Paid to Date = 134.68, New Balance Due = 1382.82. And the last line should be Payment Number = 12, Interest Paid = 1.55, Principal Paid = 133.13, Cumulative Interest = 116.17, Total Paid to Date = 1616.17, New Balance Due = 0.00.
Thank you for your help.
Yuna
Code:
#include <iostream> //for cout and cin
#include <conio.h> //for getch
#include <cmath>
#include <iomanip>
using namespace std;
void Getdata(double& Amount, double& Percent, int& Months);
void Caldata(double& Amount, double& Percent, int& Months,
double& InterestPaid, double& PrincipalPaid, double& CumlInterest, double& TotalPaidDate, double& MonthlyPayment, double& NewBalance, int& PaymentNum);
void Displaydata(double& Amount, double& Percent, int& Months, double& InterestPaid, double& PrincipalPaid, double& CumlInterest, double& TotalPaidDate, double& MonthlyPayment, double& NewBalance, int& PaymentNum);
void Displayheader(double& Amount, double& Percent, int& Months, double& MonthlyPayment);
void setvar(double& CumlInterest, double& TotalPaidDate, double& InterestPaid, int& PaymentNum, double& NewBalance, double& Amount);
void GetResponse(char& response);
int main()
{
double Amount;
double Percent;
double InterestPaid;
double PrincipalPaid;
double CumlInterest;
double TotalPaidDate;
double MonthlyPayment;
double NewBalance;
int PaymentNum;
int Months;
char response;
Getdata(Amount, Percent, Months);
Displayheader(Amount, Percent, Months, MonthlyPayment);
setvar(CumlInterest, TotalPaidDate, InterestPaid, PaymentNum, NewBalance, Amount);
do
{
Caldata(Amount, Percent, Months, InterestPaid, PrincipalPaid, CumlInterest, TotalPaidDate, MonthlyPayment, NewBalance, PaymentNum);
Displaydata(Amount, Percent, Months, InterestPaid, PrincipalPaid,
CumlInterest, TotalPaidDate, MonthlyPayment, NewBalance,
PaymentNum);
}while (PaymentNum <= Months);
GetResponse( response);
getch();
return 0;
}
void Getdata(double& Amount, double& Percent, int& Months)
{
cout << "What is the amount of the loan? ";
cin >> Amount;
cout << "What is the annual percentage rate? ";
cin >> Percent;
cout << "How many months will you take to pay back the loan? ";
cin >> Months;
while ((Percent < 1.0) || (Percent > 20.0))
{
cout << Percent << "%" << " is not a vaild interest rate.\n";
cout << "Try again. Please enter interest rate between 1% and 20% ";
cin >> Percent;
}
cout << endl;
}
void Caldata(double& Amount, double& Percent, int& Months,
double& InterestPaid, double& PrincipalPaid,
double& CumlInterest, double& TotalPaidDate,
double& MonthlyPayment, double& NewBalance, int& PaymentNum)
{
MonthlyPayment = Amount * (Percent/1200)/(1.0 - pow((1.0 + (Percent/1200)), -Months));
InterestPaid = ((Percent/100) / Months) * Amount;
CumlInterest = CumlInterest + InterestPaid;
PrincipalPaid = MonthlyPayment - InterestPaid;
TotalPaidDate = TotalPaidDate + MonthlyPayment;
NewBalance = NewBalance - PrincipalPaid ;
PaymentNum++;
Months--;
}
void Displayheader(double& Amount, double& Percent, int& Months, double& MonthlyPayment)
{
MonthlyPayment = Amount * (Percent/1200)/(1.0 - pow((1.0 + (Percent/1200)), -Months));
cout << fixed << showpoint;
cout << setw(55) << "Loan Amortization" << endl << endl;
cout << setw(15) << "Amount" << setw(25) << "Annual % Interest" << setw(15) << "Months" << setw(25) << "Monthly Payment" << endl;
cout << setprecision(2) << setw(15) << Amount << setw(18) << setprecision(2) << Percent << setw(20) << Months << setw(27) << setprecision(2) << MonthlyPayment << endl;
cout << endl << endl;
cout << "Payment" << setw(12) << "Interest" << setw(16) << "Principal" << setw(20) << "Cumlative" << setw(20) << "Total Paid" << setw(20) << "New Balance" << endl;
cout << "Number" << setw(11) << "Paid" << setw(15) << "Paid" << setw(23) << "Interest" << setw(18) << "to Date" << setw(18) << "Due" << endl << endl;
cout << "--------------------------------------------------------------------------------------------------" << endl;
}
void Displaydata(double& Amount, double& Percent, int& Months, double& InterestPaid, double& PrincipalPaid,
double& CumlInterest, double& TotalPaidDate,
double& MonthlyPayment, double& NewBalance, int& PaymentNum)
{
cout << fixed << showpoint;
cout << setw(3) << PaymentNum << setw(14) << InterestPaid << setw(17) << PrincipalPaid << setw(20) << CumlInterest << setw(20) << TotalPaidDate << setw(20) << NewBalance << endl;
}
void setvar(double& CumlInterest, double& TotalPaidDate, double& InterestPaid, int& PaymentNum, double& NewBalance, double& Amount)
{
CumlInterest = 0.0;
TotalPaidDate = 0.0;
InterestPaid = 0.0;
PaymentNum = 0;
NewBalance = Amount;
}
//do
// {
void GetResponse(char& response)
{
cout << "Do you want to continue? Y or N: " << endl;
cin >> response;
cout << endl << endl;
while (response != 'Y' && response != 'y' && response != 'N' && response != 'n')
{
cout << "You did not enter valid response. Please enter Y or N";
cin >> response;
}
}
//}while(response == 'Y' || response == 'y');