Good Afternoon,
I'm having problems with my school assignment that is about a loan program. Here are the details what the program needs to do. You are required to write a loan program for the Rio Grande Bank. This program will print an
amortization table for a loan, given the amount of the loan, the annual interest rate, and the number of
payments. This process will be repeated until the customer asks to quit. The following is a list of the
tasks that your program has to complete.
Print a welcome message.
Loop until the user wants to leave the program. In this loop, the program executes the following
three tasks.
o An input section which asks for some information including the amount of the loan, the
number of payments (in terms of months), and the annual interest rate.
o A calculation section which calculates and prints an amortization table similar to the
following for the input received from the first section. For example, given the amount of the
loan is 10000, the annual interest rate is 8% and the number of payments is 12, a table
similar to the following will be generated (may not be exact the same as yours due to
floating point errors).
Amortized Payment Schedule
month paid principal paid interest new balance
1 803.22 66.67 9196.78
2 808.57 61.31 8388.21
3 813.96 55.92 7574.25
4 819.39 50.49 6754.86
5 824.85 45.03 5930.01
6 830.35 39.53 5099.65
7 835.89 34.00 4263.77
8 841.46 28.43 3422.31
9 847.07 22.82 2575.24
10 852.72 17.17 1722.52
11 858.40 11.48 864.12
12 864.12 5.76 0.00
An output section to print out other results such as the monthly interest rate, the monthly
payment, the accumulated interest payment over the loan period, and the total payment,
along with the input parameters. For the above example, the output section should display
the following table:
Customer: John Doe
loan amount: 10000.00
annual interest rate: 8.00%
number of payments: 12
monthly interest: 0.6667% (Note: 4 decimal places!)
accumulated interest: 438.61
monthly payment : 869.89
total payment : 10438.61
To calculate and print the above tables, your program needs to calculate the monthly interest rate, the
monthly payment, and the interest portion of the payment. The following formulas are needed:
Monthly interest rate
MonIntRate = (AnnualRate/100)/12
MonthPayment = LoanAmount * MonIntRate * (1 + MonIntRate)^NumMonths/(1 + MonIntRate)NumMonths-1
MonthPaidInt = Balance * MonIntRate
MonthPrincipal = MonthPayment - MonthPaidInt
Balance = Balance - MonthPrincipal
At the end of the main loop, your program asks the customer if they would like to have another run of
the program. The loop stops if the user selects to quit. When the user quits, a farewell message should
be printed. Both the amortization table and the final print-out (the total payment etc.) should be
recorded in an output file for you to hand in.
Test data:
Amount $10,000 $10,000 $10,000 $20,000
Interest Rate 8% 7.5% 7% 7%
Months 12 12 24 24
So far I have this code for the cpp file and header
The code for cpp file is:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include "hw3.h"
using namespace std;
int main()
{
string Fname, Lname;
double loanAmount;
double annualIntRate, MonIntRate=0;
int No_of_Months;
welcome();
getCustomerInfo(Fname, Lname);
getLongInfo(loanAmount, annualIntRate, No_of_Months);
MonthlyInterestRateCalculator(annualIntRate);
MonthlyPmtCalculator(annualIntRate, loanAmount, No_of_Months, MonIntRate);
AmortizedTable(loanAmount, annualIntRate, No_of_Months);
return 0;
}
for the header file
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
#ifndef HW_3_HEAD_H
#define HW_3_HEAD_H
void welcome()
{
cout << "Welcome to Rio Grande Bank "<<endl;
cout << "We are please in assisting you in your banking needs" <<endl;
}
string getCustomerInfo(string Fname, string Lname)
{
string fullname;
cout << "Enter your first name and last name:";
cin>> Fname>>Lname;
fullname = Fname + Lname;
return fullname;
}
void getLongInfo(double& loanAmount, double& annualIntRate, int& No_of_Months)
{
cout << "Enter the loan amount that you wish to borrow:" <<endl;
cin>>loanAmount;
cout << "Enter the annual interest rate: ";
cin>>annualIntRate;
cout << "Enter the length of months of the loan ";
cin>>No_of_Months;
}
double MonthlyInterestRateCalculator(const double annualIntRate)
{
double MonIntRate;
MonIntRate = (annualIntRate/100)/12;
return MonIntRate;
}
double MonthlyPmtCalculator(double annualIntRate, const double loanAmount, const double MonIntRate, const int No_of_Months)
{
double MonthPmt;
MonthPmt = loanAmount * MonIntRate/(1 - pow(1 + MonIntRate, -No_of_Months));
return MonthPmt;
}
void AmortizedTable(const double loanAmount, const double annualIntRate, const int No_of_Months)
{
double balance, monthlyPaidInt, MonthPrincipal, MonIntRate, MonthPmt, newBalance;
MonIntRate = MonthlyInterestRateCalculator(annualIntRate);
MonthPmt = MonthlyPmtCalculator(loanAmount, MonIntRate, No_of_Months, annualIntRate);
balance = loanAmount;
cout <<"\t Amortized Payment Schedule" <<endl;
cout <<setw(6)<<left<<"Month"<<setw(12)<<left<<"Paid Principal"<<setw(14)<<right<<"Paid Interest"<<setw(12)<<right<<"New Balance"<<endl;
for (int i=1; i <= No_of_Months; i++)
{
monthlyPaidInt = balance * MonIntRate;
MonthPrincipal = MonthPmt - monthlyPaidInt;
newBalance = balance - monthlyPaidInt;
cout <<setw(6)<<left<<i<<setw(12)<<left<<MonthPrincipal<<setw(4)<<right<<monthlyPaidInt<<setw(14)<<right<<newBalance<<endl;
}
}
#endif
poloblue
-3
Newbie Poster
Recommended Answers
Jump to PostAnd what seems to be the trouble with it? I can see that it is incomplete, but you will need to spell out just what you need help with.
Seriously, PoloBlue, you have been posting here long enough that you should know better than this by now. We are not …
Jump to PostCompare:
MonthPayment = LoanAmount * MonIntRate * (1 + MonIntRate)^NumMonths/(1 + MonIntRate)NumMonths-1
with
MonthPmt = loanAmount * MonIntRate/(1 - pow(1 + MonIntRate, -No_of_Months));
You should see that they don't match. The correct code should be
MonthPmt = loanAmount * …
All 6 Replies
Schol-R-LEA
1,446
Commie Mutant Traitor
Featured Poster
poloblue
-3
Newbie Poster
Schol-R-LEA
1,446
Commie Mutant Traitor
Featured Poster
Schol-R-LEA
1,446
Commie Mutant Traitor
Featured Poster
poloblue
-3
Newbie Poster
poloblue
-3
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.