/* Loan Calculator (15 points) Write a C program that calculates the monthly payments for a mortgage loan. The program must perform the following steps: 1) read the loan amount, the number of years, and the annual interest rate (APR) from the keyboard; 2) calculate the monthly interest rate from the annual interest rate (divide by twelve); 3) compute and print the monthly payment using the formula given below; 4) compute and print the total payment, which is equal to the monthly payment times 12 times the number of years. loanAmount * monthlyInterestRate monthlyPayment = ------------------------------------------------------ 1 1 - ----------------------------------------------- (1 + monthlyInterestRate)^ (numberOfYears * 12) Where x^y means x raised to the y-th power. */ #include #include #include int main() { printf("Please enter loan amount: "); double loanAmount; scanf("%lf", &loanAmount); printf("Please enter number of years: "); int numberOfYears; scanf("%d", &numberOfYears); printf("Please enter APR: "); double APR; scanf("%lf", &APR); // calculate the monthly interest rate from the APR double monthlyInterestRate = (APR/100.0)/12.0; // compute the monthly payment double numerator = loanAmount*monthlyInterestRate; double denumerator = 1 - 1/( pow(1 +monthlyInterestRate, numberOfYears*12)); double monthlyPayment = numerator / denumerator; double totalPayment = monthlyPayment * numberOfYears * 12; printf("\nThe monthly payment is: $%g\n\n", monthlyPayment); printf("The total payment is: $%g\n\n", totalPayment); system("pause"); }