Sara wants to buy a car. Help Sara compute the monthly payment on a loan. You ha
ID: 3590819 • Letter: S
Question
Sara wants to buy a car. Help Sara compute the monthly payment on a loan. You have the following data:
You will be given the loan amount, the annual percentage rate of interest, and number of monthly payments.
Your program should allow Sara to input the loan amount, interest rate, and how many payments she wants to make.
Your program should then compute and display the monthly payment.
You need to make the following variables: Payment, LoanAmt, InterestRate, MonthlyRate, NumberMonths.
You will need the following formula: MonthlyRate = InteresteRate/1200
When the user enters InterestRate as a percentage, it must be divided by 100 to make it a decimal (i.e., 18% = 18/100 = 0.18).
The InterestRate offered by car dealers is an annual rate so this must be divided by 12 to get the MonthlyRate.
The formula in step 5 combines steps 6 and 7 (i.e., annual rate of 18% = 18/100 =0.18 and the monthly rate is 0.18/12=0.015 or 18/(100*12) = 18/1200.)
Payment = LoanAmt * MonthlyRate * (1 + MonthlyRate)^NumberMonths / ((1+MonthlyRate)^NumberMonths – 1)
This formula must be entered correctly for it to calculate the correct answer.
Think of the four stages of the Program Development Cycle: Analyze, Design, Code, and Test. Document any activities, tasks, or information that you would use in each stage to develop the program. Use Microsoft Word.
Explanation / Answer
Design:-
input data (LoanAmt,InterestRate,NumberMonths)
calculate MonthRate
calculate Payment
Code:-
#include<iostream>
using namespace std;
float power(float x, int y)
{
float sum = 1;
for(int i = 0 ;i<y;i++)
{
sum =sum * x;
}
return sum;
}
int main()
{
float Payment,LoanAmt,InterestRate,MonthlyRate;
int NumberMonths;
cout<<"Enter loan amount: ";
cin>>LoanAmt;
cout<<"Enter the annual percentage rate of interest: ";
cin>>InterestRate;
cout<<"Enter number of monthly payments: ";
cin>>NumberMonths;
MonthlyRate = InterestRate/1200;
Payment = (LoanAmt * MonthlyRate * (power((MonthlyRate+1),NumberMonths)))/((power((MonthlyRate+1),NumberMonths))-1);
cout<<"Payment: "<<Payment<<" ";
return 0;
}
Test:-
Enter loan amount: 10000
Enter the annual percentage rate of interest: 10
Enter number of monthly payments: 10
Payment: 1046.4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.