Question
You are to write a program that will develop a user-defined function, which is called from main. Your program calculates the number of the month(s)
You are to write a program that will develop a user-defined function, which is called from main. Your program calculates the number of the month(s) you need for making fixed-monthly-payments for loans using while and do~while loops. One way to calculate the monthly interest for a loan is as follows:
For the following loan:
Principal: $3,000.00
Monthly payment: $100.00
Annual interest rate: 6.72%
When the first (monthly) payment was made, its interest is calculated as follows:
The monthly interest = (principal) (annual interest rate) (30 days)/(365 days)
= $3,000 0.0672 0.08219
= $16.57
Then, the amount for paying to the principal is calculated by subtracting the monthly interest from your monthly payment as follows:
The amount for paying to the principal = $100.00 - $16.57
= $83.43
After the first monthly payment, the principal will be:
The remaining principal = $3,000 - $83.43
= $2,916.57
The above process of the monthly payments will be repeated until the principal becomes $0.00. The number of repeats in the process is the number of monthly payments before we complete the payments for the loan. For example, the above load needs a total of 33 monthly payments to complete the loan, while the total interest paid is $289.02 (we pay a total of $3,289.02).
Your program should prompt the following three inputs after it starts in the order described next. The first one is the principal (from $100.00 to $1,000,000.00). The second input is the annual interest rate (from 0.005 (0.5%) to 0.399 (39.9%)). The third input is the monthly payment amount (from $1.00 to $2,000.00). Any invalid input should be detected and they should be repeated until a valid input is made. Any valid input that has been made should not be re-prompted when an invalid input is made for other inputs.
Sample outputs for a case (principal = $3,000.00, monthly payment = $100.00, and 6.72% annual interest rate:
Requirements:
The three input parameters (principal, annual interest rate, and monthly payment amount) should be prompted and input only in main, each of which is a variable in type float.
Your program should detect invalid inputs for each of the three inputs:
for the principal: valid inputs are from $100.00 up to $1,000,000.00
for the annual interest rate: valid inputs are from 0.005 (0.5%) up to 0.399 (39.9%)
for the monthly payment amount: valid inputs are from $1.00 up to $2,000.00
If an invalid input is made, an error message should be displayed and your program should prompt a valid input.
After the first input or the second is successfully made, the first or the second input should never be prompted, when an invalid input is made to the second or the third input.
The correct number of monthly payments should be calculated in a user-defined function (Calc_Num_Months) and it should be displayed in main.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started