help me with this CSC 110 Loan Calculator You\'ve been hired to do some programm
ID: 3694740 • Letter: H
Question
help me with this
CSC 110
Loan Calculator
You've been hired to do some programming for Metro Bank. They want you to create a program to calculate loan payments. The user will enter the amount of money to borrow from the bank, the annual interest rate percentage (that will be compounded monthly) and the number of years to pay back the loan. The program will then display the monthly payment and the total amount of interest that will be paid. Also, to be more helpful to the user, display these same results using a loan amount of 10% more and 10% less.
Objectives
writing your own functions with parameters and return values
gaining more experience working with calculations
User Interface Specifications
The program should start with a basic introduction for the user (remember, this is different from the comment at the top of the file).
Prompt the user for 3 pieces of input: amount of loan in dollars, length of loan (in years), and annual interest rate. Make sure that the prompt clearly tells the user what to input and the units for each input.
For the interest rate, the user enters an annual percentage rate, such as 5 for 5%, not the decimal 0.05.
When displaying the results, first redisplay the original input.
Then, display the monthly payment and the total interest (see formulas below).
Also calculate and display these results using a loan amount of +10% and -10% to give the user a range of results. Make sure that any dollar amount is displayed with exactly 2 decimal spaces.
All displayed values need to be properly labeled.
Formulas and Code Specifications
Periodic Payment
Let:
A = amount of the loan
r = interest rate per period as a decimal, not percentage (NOTE: for this calculation, 1 period is 1 month)
n = the number of periods (i.e. the number of months)
P = the monthly payment
n = the number of months
A = amount of the loan
Then the formula to find the total interest is:
Total Interest = nP - A
Functions:
For this program, you will write a function to perform each of the calculations above. Remember that once you have written a function you need to call it to get it to execute.
Write a function defintion that is passed in the amount of the loan, the number of periods, and the interest rate per period (as a decimal) and returns the monthly payment.
Notice that the units of the parameters are the same as the units in the formula. However, these are different from the units input by the user. So you're program will need to do some conversions before calling the function.
Write a function definition that is passed in the monthly payment, the number of periods, and the amount of the original loan and returns the total interest paid. Again, be mindful of units.
Also, be aware that since you are formatting the monthly payment to 2 decimal places, that must also be the value used to calculate total interest. Otherwise, you'll have a rounding error.
Since the program needs to output 3 sets of results (results for the user input loan, as well as + 10% of loan amount and -10% of loan amount) put the code to display the output nicely into one function and call it for each set of data.
This means your program will have a total of 4 function definitions: main(), the 2 calculation functions, and a display function.
Explanation / Answer
Code:
/*
this prigram will calculate the Equal Monthly Installment(EMI)
that you have to pay for your loan
given loan amount, interest rate for annum and number of years of loan
*/
#include <stdio.h>
#include <math.h>
double monthly_payment(double loan_amount, double rate_for_month, int number_of_months);
double total_interest_paid(double payment_for_month, int number_of_months, double loan_amount);
void print_results(double loan_amount,double rate_for_month, int number_of_months);
int main()
{
double A,rate,r;
int years,n;
printf("this prigram will calculate the Equal Monthly Installment(EMI) ");
printf("that you have to pay for your loan ");
printf("given loan amount, interest rate for annum and number of years of loan ");
printf("enter loan amount ");
scanf("%lf",&A);
printf("enter interest rate per annum ");
scanf("%lf",&rate);
r=rate/1200;
printf("enter number of years you want to take the loan ");
scanf("%d",&years);
n=years*12; // number of months = years*12
printf(" results for actual loan amount ");
print_results(A,r,n); // for actual loan
printf(" results for 10 percent less of actual loan amount ");
print_results(A*0.9,r,n); // for loan amount = 10% less
printf(" results for 10 percent more of actual loan amount ");
print_results(A*1.1,r,n); // for loan amount = 10% more
return 0;
}
void print_results(double loan_amount,double rate_for_month, int number_of_months)
{
double payment_for_month,interest_to_be_paid;
payment_for_month = monthly_payment(loan_amount,rate_for_month,number_of_months);
interest_to_be_paid = total_interest_paid(payment_for_month,number_of_months,loan_amount);
printf("Loan amount = $%.2f ",loan_amount);
printf("monthly payment to be paid = $%.2f ",payment_for_month);
printf("Total interest to be paid for this loan = $%.2f ",interest_to_be_paid);
}
double monthly_payment(double loan_amount, double rate_for_month, int number_of_months)
{
double temp;
temp = pow(1+rate_for_month, number_of_months*(-1));
return (loan_amount*rate_for_month)/(1-temp);// monthly payment = Ar/(1 - (1+r)^-n)
}
double total_interest_paid(double payment_for_month, int number_of_months, double loan_amount)
{
return payment_for_month*number_of_months - loan_amount;
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.