IR - Tom Kleen
C Functions: Loan repayment scheduleUpdated DATE \@ "yyyy-MM-dd" \* MERGEFORMAT 2021-02-06PrerequisitesUse printf to print values to the screen Use scanf to input values from the keyboard (see format string "%lf").Format floating point data types with a fixed number of decimal places when using printf.Write a function.Know (find on the internet) the formula for computing the payment on a loan.Use (include) the math.h file and read about the pow function.Write a while loop.Write a for loop.Write an if statement.Input, processing, outputWrite a C program that will retrieve from the user (keyboard/stdin) values to the following three variables: years (an int), loanAmount (double), and annualRate (double). Write a function to compute the monthly payment (assume that all payments are made monthly). Pass in: (1) the loan amount, (2) the annual interest rate, and (3) the number of years. Note that the annual interest rate will have to be converted into a monthly interest rate and that the number of years will have to be converted into the number of months. Return the monthly payment (a double). Display the payment on a line by itself, with two decimal places. On subsequent lines, print (1) the payment number (right-aligned in a 3-column field), (2) the amount of this payment that goes towards interest, (3) the amount of this payment that goes towards the principal, and (4) the new balance after making the payment. Display all of the dollar values (items 2-4) in a 14-column field with two digits to the right of the decimal point. Do this repeatedly until the user enters 0 for the loan amount.To help you check your output, I have provided the first 3 and last 3 lines of a sample execution below. Note that the rate 12% is entered as 12. It must be divided by 100 to convert it from 12 to 12% (0.12), and then divided by 12 to get the monthly rate. Note that if the number of years is 30, your output will have 360 payments.Sample execution:Enter the loan amount (0 to quit): 50000Enter the annual rate: 12Enter the number of years: 30Payment: 514.31 No. Payment Interest Principal Balance 1 514.31 500.00 14.31 49985.69 2 514.31 499.86 14.45 49971.24 3 514.31 499.71 14.59 49956.65…358 514.31 15.13 499.18 1013.39359 514.31 10.13 504.17 509.21360 514.31 5.09 509.21 -0.00Enter the loan amount (0 to quit): 100000Enter the annual rate: 5.25Enter the number of years: 15Payment: 803.88 No. Payment Interest Principal Balance 1 803.88 437.50 366.38 99633.62 2 803.88 435.90 367.98 99265.64 3 803.88 434.29 369.59 98896.05...178 803.88 10.46 793.42 1597.27179 803.88 6.99 796.89 800.38180 803.88 3.50 800.38 0.00Enter the loan amount (0 to quit):0End of program.Things to note:The ending balance for the first example is -0.00. Negative zero? The actual balance is a very small fraction of a penny below 0, but we are only displaying 2 decimal places. If we displayed more decimal places, we would see that the actual value is -0.0000000001177796, which for all practical purposes is 0.Note that the interest for each period is determined by multiplying the remaining balance on the loan by the interest rate. After you compute the interest, you can subtract it from the payment to determine the portion of the payment going to pay off the principal. The new balance is the old balance minus the portion of the payment that was used to pay down the principal. For example, above, the interest for the first period is $500 because that is $50,000 * 1% (12%/12). The payment is 514.31, so if $500 of that is going to pay interest, then the rest ($514.31 - $500) is going to pay down the principal. So the principal will be reduced by $14.31, leaving a new balance of $49,985.69.Note that sometimes if you check the arithmetic by hand, the ending balance may be off by a penny. This is because the double data type keeps track of 15 significant digits, but we are only printing out 7 or fewer. Don't worry about this. However, if you want a little more to do, try to figure out how to round off your answers to 2 decimal places every time you compute the data for a payment. If you do this, you will have to have special logic for your final payment because you will be off by a little bit, due to accumulation of round-off errors!Your ending balance may be -0.00. Again, this is because of the fact that the double data type keeps track of 15 significant digits. The final balance may be slightly less than 0 (way out around the 10th decimal place or so), but we are displaying it rounded off to the nearest penny, so we get a "0" with a negative sign. To format your output, check out the printf method.Use the double type for floating point values, the int type for integer values. Call your program Loan.c and put it in the drop box. ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- blackrock ir sec filings
- cpt codes for ir procedures
- ir cpt code list
- ir spectroscopy pdf
- ir spectroscopy of co2
- ir spectroscopy practice
- ir spectra database
- ir spectroscopy problems and answers
- ir spectroscopy practice problems pdf
- ir spectroscopy problems
- ir spectra practice problems
- ir practice problems and answers