Goals to use a sentinel controlled loop to use functions L

Goals:

• to use a sentinel controlled loop

• to use functions

Loan Schedule

Overview

In this lab assignment, you will develop a C++ program that will calculate and display a loan payment schedule. The expected input and output format is shown below.

Remember to document your program. Include the comments at the top with name, date, class, purpose, etc. But also include comments throughout your program to show what you’re doing. Each function should have at least one comment. Your program will be read, please make it easy to understand! This includes the proper use of white space.

Example Input and Output (The actual input is shown in bold.)

This program will calculate and display your payment schedule for a loan.

Please enter the balance on your loan: $1000.00
Please enter the annual interest rate: 9
Please enter your monthly payment: $90.00

Payment Balance Interest Principle

1 917.50 7.50 82.50

2 834.38 6.88 83.12

3 750.64 6.26 83.74

4 666.27 5.63 84.37

5 581.27 5.00 85.00

6 495.63 4.36 85.64

7 409.34 3.72 86.28

8 322.41 3.07 86.93

9 234.83 2.42 87.58

10 146.59 1.76 88.24

11 57.69 1.10 88.90

Final Payment of: 58.12

With a payment of $90.00, it will take you

12 months to pay off your loan of $1000.00.

You will pay $48.12 in interest.

Input Specifications

Your program should ask the user for the balance of the loan, the annual interest rate and the monthly payment amount. These values can have decimal places! You should not accept any negative values – if the user enters a negative value, you should continue prompting them for a value until you get a valid value.

Output Specifications

The output should be as shown above. You should output the payment schedule. For each payment made, you should show the balance remaining after the payment, how much of the payment went to interest and how much went to principle. Remember to use the formatting methods that we learned earlier in the semester to obtain the correct spacing, alignment and precision.

Interface Descriptions

You must include the functions described here. The things that a function accepts will be input parameters. If a function returns only one value, you should use a return type on your function to return the value. If a function returns more than one value, you should use a “void” return type and return the values using reference parameters.

Function getInput():Get balance of loan, annual interest rate and monthly payment from the user.

Accepts:   Output parameters for balance, annual interest rate and monthly payment.

Returns:Balance, annual interest rate and monthly payment.

Function calcSchedule():Calculate the monthly payment schedule of a loan.

Accepts:     Balance, annual interest rate, monthly payment and output parameters for total

interest and term (the term is the duration – in months -- of the loan).

Returns:Total interest and term.

Function printSummary():Prints the summary of the loan information (shown in output

display above – “With a payment of…”.

Accepts:Payment, balance, term and total interest.

Returns:   nothing

The main program should call these functions in the order shown above. Remember to use function prototypes when writing these functions.

Calculating the Payment Schedule

You will be calculating the payment schedule after monthly loan payments. But the user has given you an annual interest rate. So you should convert the interest rate for the entire year into a monthly interest rate by dividing it by 12. However, this is still a percentage value. To use it in calculations, you will need it in decimal form. Remember, 10% is .1 in decimal form.

Each month, the interest due on the balance is calculated first. You calculate the interest due by multiplying the remaining loan balance by the monthly interest rate.

To determine how much principle will be paid off that month, you can subtract the interest due from the monthly payment.

The new loan balance can then be calculated by subtracting the principle from the loan balance.

Once the loan balance is less than the monthly payment, you should print out the final payment. This final payment is computed as the sum of the remaining balance and the interest due on that balance.

Getting Started

As you know, it’s always easier to do your programming assignments in small steps. Here are some ideas to get you started:

• Write your getInput function and get it working. To test that it’s working, display the variables in your main program to make sure that you’ve received the proper values from your function.

• Begin working on your calcSchedule function.

o Calculate the values for the first month’s payment, and display them in the appropriate table format.

o Figure out how to do the loop for calculating the payment schedule. You don’t have to display the payment number yet. Also, you don’t need to worry about figuring out the term or the total interest right away. Your final payment may not be right, as long as the values for the table are correct.

o Now work on getting the final payment to display correctly.

o Finally, figure out how to calculate the total interest and the term of the loan.

• Write your printSummary function.

Testing

Be sure to test your program with a variety of input values, so that you can be sure that your calculations are correct.

Solution

#include <iostream> // input output file
#include <iomanip> // std::setprecision

// DO NOT CHANGE ANYTHING BELOW
using namespace std;
// function declaration
int payoff(double l,double p,double i);
int main()
   {   
          
           double loan, payment, interest;   
          
           cout.setf(ios::fixed, ios::floatfield);        //configure precision
           cout.precision(2);                                //set to precision 2;
           cout << \"Please enter loan amount: \";   
          
           cin >> loan;                                     //read loan amount
           cout << loan << endl;   
          
           cout << \"Please enter monthly payment: \";   
          
           cin >> payment;                                     //read monthly paymnet
          
           cout << payment << endl;   
          
           cout << \"Please enter annual interest: \";   
          
           cin >> interest;                                 //read annuval rate
           cout << interest << endl;   
           cout <<\"Interest rate per month is\" << (interest/12)<<endl;;
          
           int numMonths = payoff(loan, payment, interest);        //function call to payoff
          
           if (numMonths != -1)                                    //if numMonts is equal to -1 report error otherwise display numMonths
           {
          
           cout << \"It will take \" << numMonths;
          
           cout << \" months to pay off the loan.\" << endl;

       }
           else
           cout << \" Report was stopped, does not seem to end.\" << endl;

return 0;

   }
int   payoff(double l,double p,double i)
   {
       int x;
       float sum=0,nop=0,tsum=0;
      
       for ( x=0;l>p;x++)                   //loop for finding number months to monthly installments
       {
      
           if(nop<=360)                   //check months crosses to 360
           {
              
           sum=(l*(i/12)*1)/100;           //loan * interest per month * one month
           tsum=sum+l;                           //tsum with principal amount with interest
           cout << \"Mon: \"<<x+1<<\" Bal:\" <<l <<\" + Int:\"<<sum << \"- Pay: \"<<p <<endl; //dispaly output in required format
           l=tsum-p;                       //laon amount reduced after monthly paymnet;
              
       }
       else
       {
          
           return -1;
           }
          
           nop++;
       }
       if(l>0)                   //last month remaing amount grater than zero
       {
           cout<< \"Last payment: \" << l <<endl ;
           x=x+1;
           return x;
       }
       else
       {
           return x;
       }
      
      
   }

Output :

Please enter loan amount: 1000
1000.00
Please enter monthly payment: 90
90.00
Please enter annual interest: 9
9.00
Interest rate per month is0.75
Mon: 1 Bal:1000.00 + Int:7.50- Pay: 90.00
Mon: 2 Bal:917.50 + Int:6.88- Pay: 90.00
Mon: 3 Bal:834.38 + Int:6.26- Pay: 90.00
Mon: 4 Bal:750.64 + Int:5.63- Pay: 90.00
Mon: 5 Bal:666.27 + Int:5.00- Pay: 90.00
Mon: 6 Bal:581.27 + Int:4.36- Pay: 90.00
Mon: 7 Bal:495.63 + Int:3.72- Pay: 90.00
Mon: 8 Bal:409.34 + Int:3.07- Pay: 90.00
Mon: 9 Bal:322.41 + Int:2.42- Pay: 90.00
Mon: 10 Bal:234.83 + Int:1.76- Pay: 90.00
Mon: 11 Bal:146.59 + Int:1.10- Pay: 90.00
Last payment: 57.69
It will take 12 months to pay off the loan.

Goals: • to use a sentinel controlled loop • to use functions Loan Schedule Overview In this lab assignment, you will develop a C++ program that will calculate
Goals: • to use a sentinel controlled loop • to use functions Loan Schedule Overview In this lab assignment, you will develop a C++ program that will calculate
Goals: • to use a sentinel controlled loop • to use functions Loan Schedule Overview In this lab assignment, you will develop a C++ program that will calculate
Goals: • to use a sentinel controlled loop • to use functions Loan Schedule Overview In this lab assignment, you will develop a C++ program that will calculate
Goals: • to use a sentinel controlled loop • to use functions Loan Schedule Overview In this lab assignment, you will develop a C++ program that will calculate

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site