Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Time it took Matthew: 5 minutes Files to submit: loan_cost.c Requriements: Progr

ID: 3587968 • Letter: T

Question

Time it took Matthew: 5 minutes

Files to submit: loan_cost.c

Requriements:

Program must compile with both -Wall and -Werror options enabled

Submit only the files requested

Use doubles to store real numbers

Print all doubles to 2 decimal points unless stated otherwise

Problem Desciption

Loans can be rather expensive in the long run so it is important to figure out how much money you will be paying each month as well as the total cost of the loan. The formula for calculating the peoridic payment of the loan is

where

P is the principal (amount of money borrowed)

i is the interest rate

n is the total number of payments

Your program should ask the user for the following in this order

The amount they are borrowing

The annual interest rate

We will be assuming that the payments are being made monthly so the actual interest to use is 1/12 of the annual interest

The number of payments to be made

After collecting the above information your program report the monthly payment as well as the total cost of the loan.

Assumptions

All input is valid

As stated before, we will be assuming that payments are made monthly (the norm) and so you will want to use 1/12 of the annual interest in your calculations

The examples provided do not represent all possible input you can receive

So make sure to test throughly on your machine

Additional Notes

You will need to use pow function in this assignment so don't forget to include math.h and compile with -lm.

Examples

In the examples below user input has been underlined. You don't have to do any underlining in your program. It is just there to help you differentiate between what is input and what is output.

Example 1

Please enter the amount of money you borrowed: $1000

Please enter the annual interest rate: .05

Please enter the number of payments to be made: 12

A loan of $1000.00 with an annual interest of 0.05 payed off over 12 months will have monthly payments of $85.61.

In total you will pay $1027.29, making the cost of your loan $27.29.

Example 2

Please enter the amount of money you borrowed: $60000

Please enter the annual interest rate: .07

Please enter the number of payments to be made: 120

A loan of $60000.00 with an annual interest of 0.07 payed off over 120 months will have monthly payments of $696.65.

In total you will pay $83598.11, making the cost of your loan $23598.11.

Explanation / Answer

#include <iostream>

using namespace std;

int main()

{

double monthlyPayment;

double balance;

double interestRate;

cout.setf(ios::fixed);

cout.setf(ios::showpoint);

cout.precision(2);

cout << "Enter the current balance of your loan: $";

cin >> balance;

cout << "Enter the interest rate (compounded monthly) : ";

cin >> interestRate;

cout << "Enter the desired monthly payment : $";

cin >> monthlyPayment;

while (interestRate >= 1)

{

interestRate = interestRate / 100;

}

balance = balance * (1 + interestRate / 12) - monthlyPayment;

cout << "Your new balance is : $" << balance << endl;

// The program stops here and doesn't complete the loop that follows.

// This is where I'm stuck

while (balance >0)

{

balance = balance * (1 + interestRate / 12) - monthlyPayment;

cout << "Your balance is now : $" << balance << endl;

}

cout << "You have paid off the loan at this point. Congratulations!";

return 0;

}

Edit & Run

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote