Need some help with this code. It is pretty much a loan repayment calculator. The company only offers 10, 15, and 30 year fixed loans. The interest rates are based off the customers credit score. Based on the customer’s credit score, the program will randomly generate an interest rate based on the following ranges:
Rating Interest Rate
Excellent 2.75% - 4.00%
Good 4.01% - 6.50%
Fair 6.51% - 8.75%
Bad 8.76% - 10.50%
To receive credit for this assignment, certain programming features must be implemented in such a way as to demonstrate your knowledge of random number generation, use of enums, proper formatting of output, input error checking, switch statements, and if statements.
Must prompt user to enter loan amount and credit score. ensure that the credit score entered does not exceed 850. If a non-numeric, negative, or score that exceeds 850 is entered, prompt the user to re-enter the score.
If the credit score is below 300, display an error message to the user stating that the loan cannot be offered and exit the program. Valid terms are 10, 15, and 30 years. Any other numbers should be rejected, and the user should be prompted to re-enter an appropriate value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#include <iostream>
#include <iomanip> // setprecision() setw()
#include <cmath> // pow(6, 2) 6^2
using namespace std;
int main()
{
// Constant
const int ONE = 1,
HUNDRED = 100,
NUMBER_OF_MONTHS = 12;
// Variables
int N;
float Rate,
L,
Payment,
amount_paid_back,
interest_paid;
// Ask the user for Rate, number of paymets, and amount of the loan
cout << endl;
cout << "What is interest rate of the loan? %";
cin >> Rate;
cout << "What is the Amount of the loan? ";
cin >> L;
cout << "Number of payments? ";
cin >> N;
// Calculation
Rate /= NUMBER_OF_MONTHS;
Rate /= HUNDRED; // 4.25% == .0425
// Payment = [Rate * (1 + Rate)^N / ((1 + Rate)^N - 1)] * L
Payment = ((Rate) * pow(ONE + (Rate), N) / (pow(ONE + (Rate), N) - ONE)) * L;
Rate *= HUNDRED; // .0425 == 4.25
amount_paid_back = N * Payment;
interest_paid = (N * Payment) - L;
// Display
/************************************************
* Loan Amount: $ 10000.00 *
* Monthly Interest Rate: 1% *
* Number of Payments: 36 *
* Monthly Payment: $ 332.14 *
* Amount Paid Back: $ 11957.15 *
* Interest Paid: $ 1957.15 *
************************************************/
cout << setprecision(2) << fixed << right << endl;
cout << "Loan Amount: $";
cout << setw(10) << L << endl;
cout << "Monthly Interest Rate: ";
cout << setw(10) << Rate << '%' << endl;
cout << "Number of Payments: ";
cout << setw(10) << N << endl;
cout << "Monthly Payment: $";
cout << setw(10) << Payment << endl;
cout << "Amount Paid Back: $";
cout << setw(10) << amount_paid_back << endl;
cout << "Interest Paid: $";
cout << setw(10) << interest_paid;
cout << endl << endl;
// Terminate Program
return 0;
}
|