Question

In: Computer Science

CODE IN C++ PLEASE When you borrow money to buy a house, a car, or for...

CODE IN C++ PLEASE

When you borrow money to buy a house, a car, or for some other purpose, you repay the loan by making periodic payments over a certain period of time. Of course, the lending company will charge interest on the loan. Every periodic payment consists of the interest on the loan and the payment toward the principal amount. To be specific, suppose that you borrow $1,000 at an interest rate of 7.2% per year and the payments are monthly. Suppose that your monthly payment is $25. Now, the interest is 7.2% per year and the payments are monthly, so the interest rate per month is 7.2/12 = 0.6%. The first month’s interest on $1,000 is 1000 X 0.006 = 6. Because the payment is $25 and the interest for the first month is $6, the payment toward the principal amount is 25 - 6 = 19. This means after making the first payment, the loan amount is 1,000 - 19 = 981. For the second payment, the interest is calculated on $981. So the interest for the second month is 981 X 0.006 = 5.886, that is, approximately $5.89. This implies that the payment toward the principal is 25 - 5.89 = 19.11 and the remaining balance after the second payment is 981 - 19.11 = 961.89. This process is repeated until the loan is paid. Instructions Write a program that accepts as input: The loan amount The interest rate per year The monthly payment. (Enter the interest rate as a percentage. For example, if the interest rate is 7.2% per year, then enter 7.2.) The program then outputs the number of months it would take to repay the loan. (Note that if the monthly payment is less than the first month’s interest, then after each payment, the loan amount will increase.) In this case, the program must warn the borrower that the Monthly payment is too low. The loan cannot be repaid. Since your program handles currency, make sure to use a data type that can store decimals with a decimal precision of 2.

Solutions

Expert Solution

The c++ program to calculate the number of months required to pay the money is as follows :

________________________________________________________________________________________________

#include<iostream>
using namespace std;
//Function to round a floating point number to two decimal places
float presetting(float num)
{
  
int t = num*100; //The float number accepted is multiplyed by 100
   if(t%10>5)
   {
       //If the last digit is grater than five, .5 is added and the number is rounded to two decimal places and returned
       float interest =(int)(num*100+.5);
       return (float)interest/100;
   }
   else
   { //else the number is rounded to two decimal places and returned
       float interest =(int)(num*100);
       return (float)interest/100;
   }
  
}

int main()
{
   float principal,rate,monamt,interest;
   /*
   variables are declared as follows
   principal will hold the principal amount.
   rate will hold the annual interest rate.
   monamt is the montly amount installment.
   interest is declared to hold the interest per month
   */
  
   //Taking the user inputs
   cout<<"\nEnter the Principle amount :$ ";
   cin>>principal;
   cout<<"\nEnter the interest rate : ";
   cin>>rate;
   cout<<"\nEnter the monthly installment amount : $";
   cin>>monamt;
   rate = rate/1200;
  
   int count=0; //Count will count the number of month required to pay the loan
       while(principal>0)
       {   
       interest = principal*rate; //Interest is calculated
       interest = presetting(interest);//Interest is rounded off to two decimal places
      
       if(interest > monamt)
           { //Giving warning to user if the monthly payment is lower than monthly interest amount
               cout<<"monthly payment is too low, and with this monthly payment, the loan amount could not be repaid.";
               return 0;
           }
           count++;
           principal = principal-(monamt-interest);//calculating the remaining principal
           principal = presetting(principal);
          
       }
   cout<<"Total No Of Months required to pay the loan is : "<<count;
   return 0;
}

____________________________________________________________________________________________

The output of the program is


Related Solutions

When you make a large purchase (say, a house or a car) you typically borrow money...
When you make a large purchase (say, a house or a car) you typically borrow money from lenders (e.g. banks, mortgage brokers, credit unions, etc.) who frequently quote the interest you are going to pay in two ways. First, they quote an annual 'interest rate' - the number they widely advertise (but which is often inaccurate), and then a higher (sometimes, much higher) "APR"- which they don't advertise but HAVE to disclose in the fine print because of regulation. The...
When you make a large purchase (say, a house or a car) you typically borrow money...
When you make a large purchase (say, a house or a car) you typically borrow money from lenders (e.g. banks, mortgage brokers, credit unions, etc.) who frequently quote the interest you are going to pay in two ways. First, they quote an annual 'interest rate' - the number they widely advertise (but which is often inaccurate), and then a higher (sometimes, much higher) "APR"- which they don't advertise but HAVE to disclose in the fine print because of regulation. The...
You will buy a new car today.  You will borrow the full price of the car.  You will...
You will buy a new car today.  You will borrow the full price of the car.  You will get a FIVE  year loan that will be paid back annually.  It will take you the full FIVE  years to pay back the loan.  (In other words, you will not pay it off early.)  You will pay back the same amount every year (an annuity). The auto dealership offers you 3 choices. 1)  Pay $30,000 for the car at 0% interest for the FIVE  years.    2)  Pay $28,000 for the car at...
You plan to borrow $500,000 to buy a house. The amortization period of the mortgage is...
You plan to borrow $500,000 to buy a house. The amortization period of the mortgage is 20 years. You obtain a 5-year fixed rate mortgage from TD bank at 2%/year (using Canadian mortgage convention). (a) How much do you owe the bank after the 60th payment? (b) For the 24th monthly payment, how much of it is for interest, and how much of it is for principal repayment? d) What is the present value of the interest portion of the...
You plan to borrow $500,000 to buy a house. The amortization period of the mortgage is...
You plan to borrow $500,000 to buy a house. The amortization period of the mortgage is 20 years. You obtain a 5-year fixed rate mortgage from TD bank at 2%/year (using Canadian mortgage convention). (a) What is your monthly payment? (b) How much do you owe the bank after the 60th payment? (c) For the 24th monthly payment, how much of it is for interest, and how much of it is for principal repayment? (d) What is the present value...
You want to buy a house and will need to borrow $245,000. The interest rate on...
You want to buy a house and will need to borrow $245,000. The interest rate on your loan is 5.77 percent compounded monthly and the loan is for 30 years. What are your monthly mortgage payments?
You borrow $29,000 to buy a car. You plan to payoff the car within 6 years...
You borrow $29,000 to buy a car. You plan to payoff the car within 6 years and the APR on the car loan is 2.99%. Using an excel to create an amortization for this car payment for 72 months. Please print out your excel and turn it in for 6 points extra credit on the test. You need to turn in your own work. Can you post 24-61 please? Month Beginning Balance Monthly Payment Interest Paid Principal Paid Ending Balance...
You borrow $29,000 to buy a car. You plan to payoff the car within 6 years...
You borrow $29,000 to buy a car. You plan to payoff the car within 6 years and the APR on the car loan is 2.99%. Using an excel to create an amortization for this car payment for 72 months. Please print out your excel and turn it in for 6 points extra credit on the test. You need to turn in your own work. Month Beginning Balance Monthly Payment Interest Paid Principal Paid Ending Balance 1 2 3 ... 72...
If you borrow to buy a new car, which of the following items on the balance...
If you borrow to buy a new car, which of the following items on the balance sheet will be affected? unable to determine debts only assets and debts assets only
You borrow $24,000 to buy a car. The loan is to be paid off in quarterly...
You borrow $24,000 to buy a car. The loan is to be paid off in quarterly installments over four years at 10 percent interest annually. The first payment is due one quarter from today. What is the amount of each quarterly payment? a) $1,745 b) $1,794 c) $1,838 d) $1,876 I need the hand-written formula, not the calculator input.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT