Instructions : The following programming problem can be solved by a program that
ID: 3573226 • Letter: I
Question
Instructions: The following programming problem can be solved by a program that performs three basic tasks (Input Data, Process Data, Output Results) along with selection and repetition coding techniques. Starting with the program you created in Programming Project 1 and using RAPTOR, design a suitable program to solve this problem.
Problem Statement
A finance company provides loans for motorcycles at different rates depending on how much the total loan amount is and how many payments will be made on the loan. Using the information in the table below, write a program that will calculate the monthly payment based on user inputs of loan amount and number of monthly payments. The user will NOT input the percentage rate, as this will be determined by the program code based on user input of loan amount and number of payments. The output will display the loan amount, number of payments, monthly payments and the interest rate of the loan. Use a loop to allow users to enter as many sets of data as desired. At the end of each loop, ask the user if he or she would like to Exit the program (Y for Yes or N for No). If yes, clear the variables and repeat the input, processing and output loop. If no, exit the program.
If the user enters data that is "out of bounds" (loan amount/number of payments below or above minimum/maximum in table), display an error message explaining the situation to the user and ask for the loan amount or number of payments (whichever one was out of bounds) again. Message Example: "We do not finance loans below $500."
You MUST use Modular Programming techniques by using Sub Modules (Sub Charts in RAPTOR) in your program. Your "main" module should not be very large.
Amount of Loan $500-$2,500 $2,501 $10,000 $10,001 or above Problem Statement of Payments 6-12 13-36 37-48 6-12 13-36 37-48 6-12 13-36 37-48 Interest Rate Applied 8% 10% 12% 7% 6% 5% 60% 7%Explanation / Answer
#include<iostream>
using namespace std;
//Validates the Loan amount
int validateAmount(int l)
{
la5:
//If less than 500 re enter the amount
if(l < 500)
{
cout<<" We do not finance loans below $500. Re enter the loan amount: ";
cin>>l;
goto la5;
}
return l;
}
//Validates the Number of payment
int validatePay(int p)
{
la6:
//If less than 6 re enter the number of slot
if(p < 6)
{
cout<<" Number of payment cannot be less than 6. Re enter the Number of Payment: ";
cin>>p;
goto la6;
}
la48:
//If greater than 48 re enter the number of slot
if(p > 48)
{
cout<<" Number of payment cannot be more than 48. Re enter the Number of Payment: ";
cin>>p;
goto la48;
}
else
return p;
}
//Accept and returns the validate loan amount
int AcceptLoan()
{
int ll;
cout<<" Enter Loan Amount: ";
cin>>ll;
return validateAmount(ll);
}
//Accept and return the validate number of payment
int AcceptPay()
{
int pp;
cout<<" Enter Number of Payment: ";
cin>>pp;
return validatePay(pp);
}
//Calculates and returns the monthly payment
float monthlyPay(int l, int p)
{
return ((float)l / p);
}
//Returns the interest rate
int interestRate(int l, int p)
{
if(l >= 500 && l <= 2500)
{
if(p >= 6 && p <= 12)
return 8;
else if(p >= 13 && p <= 36)
return 10;
else
return 12;
}
else if(l >= 2501 && l <= 10000)
{
if(p >= 6 && p <= 12)
return 7;
else if(p >= 13 && p <= 36)
return 8;
else
return 6;
}
else
{
if(p >= 6 && p <= 12)
return 5;
else if(p >= 13 && p <= 36)
return 6;
else
return 7;
}
}
//Displays the result
void show(int l, int p, float mp, int i)
{
cout<<" Amount "<<l;
cout<<" Payment: "<<p;
cout<<" Monthly Payment: "<<mp;
cout<<" Interest: "<<i;
}
int main()
{
int loanAmount, noOfPayment, Interest;
float mPay;
char ch;
//Loops till N is entered
do
{
loanAmount = AcceptLoan();
noOfPayment = AcceptPay();
mPay = monthlyPay(loanAmount, noOfPayment);
Interest = interestRate(loanAmount, noOfPayment);
show(loanAmount, noOfPayment, mPay, Interest);
cout<<" Would you like to continue: (Y/N)";
cin>>ch;
if(ch == 'N' || ch == 'n')
break;
}while(1);
}
Output:
Enter Loan Amount: 300
We do not finance loans below $500.
Re enter the loan amount: 105222
Enter Number of Payment: 45
Amount 105222
Payment: 45
Monthly Payment: 2338.27
Interest: 7
Would you like to continue: (Y/N)y
Enter Loan Amount: 5000
Enter Number of Payment: 3
Number of payment cannot be less than 6.
Re enter the Number of Payment: 32
Amount 5000
Payment: 32
Monthly Payment: 156.25
Interest: 8
Would you like to continue: (Y/N) N