Question

I've created a mortgage calculator and the next step in my project is to include an...

I've created a mortgage calculator and the next step in my project is to include an array. I'm not very good at C++ as this is my first time taking a programming course. I was able to get this working but I'm confused as to where I could use an array. I was thinking of maybe using the person's credit score as an indication of what their interest rate could be for a HELOC. Something like this : int creditScore[3]={2.8, 3.0, 3.4} .

this is the code I'm working with right now, any help on how to include an array would be very much appreciated.

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
// Constant
const int
ONE = 1,
HUNDRED = 100,
NUMBER_OF_MONTHS = 12;

// Variables
int loanLength, creditScore;

float
Rate,
loanAmnt,
Payment,
totalPaid,
interestPaid;
//Program Title
cout << "Mortgage Calculator";
cout << endl << endl;
// Ask the user for loan amount, rate and mortgage years
cout << endl;
cout << "What is the Amount of the loan? ";
cin >> loanAmnt;
cout << "What is your credit score? ";
cin >> creditScore;
cout << "Mortgage Period (Years)? ";
cin >> loanLength;

{
if (creditScore >= 800)
{
Rate = 2.8;
cout << "Your interest rate is 2.8%" << endl;
}
else if (creditScore >= 780)
{
Rate = 3.0;
cout << "Your interest rate is 3.0%" << endl;
}
else if (creditScore >= 760)
{
Rate = 3.4;
cout << "Your interest rate is 3.4%" << endl;
}
else if (creditScore >= 740)
{
Rate = 3.8;
cout << "Your interest rate is 3.8%" << endl;
}
else if (creditScore >= 720)
{
Rate = 4.2;
cout << "Your interest rate is 4.2%" << endl;
}
else if (creditScore >= 700)
{
Rate = 4.6;
cout << "Your interest rate is 4.6%" << endl;
}
}


// Calculation
Rate /= NUMBER_OF_MONTHS;

Rate /= HUNDRED; // 4.25% == .0425

// Payment = [Rate * (1 + Rate)^(loanLength*12) / ((1 + Rate)^(loanLength*12) - 1)] * loanAmnt
Payment = ((Rate)*pow(ONE + (Rate), (loanLength * 12)) / (pow(ONE + (Rate), (loanLength * 12)) - ONE)) * loanAmnt;

Rate *= HUNDRED; // .0425 == 4.25

totalPaid = (loanLength * 12) * Payment;

interestPaid = ((loanLength * 12) * Payment) - loanAmnt;

// Display information to user
cout << setprecision(2) << fixed << right << endl;

cout << "Loan Amount: $";
cout << setw(10) << loanAmnt << endl;

cout << "Monthly Interest Rate: ";
cout << setw(10) << Rate << '%' << endl;

cout << "Number of Payments: ";
cout << setw(10) << (loanLength * 12) << endl;

cout << "Monthly Payment: $";
cout << setw(10) << Payment << endl;

cout << "Total Amount Paid: $";
cout << setw(10) << totalPaid << endl;

cout << "Interest Paid: $";
cout << setw(10) << interestPaid;

cout << endl << endl;

system("pause");
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

// Defines main function
int main()
{
// Constant
const int ONE = 1, HUNDRED = 100, NUMBER_OF_MONTHS = 12;

// Variables
int loanLength, creditScore;
float rate, loanAmnt, payment, totalPaid, interestPaid;
// Declares an float array for rate of interest
const float rateInterest [] = {2.8f, 3.0f, 3.4f, 3.8f, 4.2f, 4.6f, 4.9f};

// Displays program Title
cout << "Mortgage Calculator";
cout << endl << endl;
// Ask the user for loan amount, rate and mortgage years
cout << endl;
cout << "What is the Amount of the loan? ";
cin >> loanAmnt;
cout << "What is your credit score? ";
cin >> creditScore;
cout << "Mortgage Period (Years)? ";
cin >> loanLength;

// Checks if credit score is greater than or equals to 800
if (creditScore >= 800)
{
// Assigns the 0 index position data to rate
rate = rateInterest[0];
cout << "Your interest rate is "<<rate<<"%"<< endl;
}// End of if condition

// Otherwise checks if credit score is greater than or equals to 780
else if (creditScore >= 780)
{
// Assigns the 1 index position data to rate
rate = rateInterest[1];
cout << "Your interest rate is "<<rate<<"%"<< endl;
}// End of else if condition

// Otherwise checks if credit score is greater than or equals to 760
else if (creditScore >= 760)
{
// Assigns the 2 index position data to rate
rate = rateInterest[2];
cout << "Your interest rate is "<<rate<<"%"<<endl;
}// End of else if condition

// Otherwise checks if credit score is greater than or equals to 740
else if (creditScore >= 740)
{
// Assigns the 3 index position data to rate
rate = rateInterest[3];
cout << "Your interest rate is "<<rate<<"%"<< endl;
}// End of else if condition

// Otherwise checks if credit score is greater than or equals to 720
else if (creditScore >= 720)
{
// Assigns the 4 index position data to rate
rate = rateInterest[4];
cout << "Your interest rate is "<<rate<<"%"<< endl;
}// End of else if condition

// Otherwise checks if credit score is greater than or equals to 700
else if (creditScore >= 700)
{
// Assigns the 5 index position data to rate
rate = rateInterest[5];
cout << "Your interest rate is "<<rate<<"%"<< endl;
}// End of else if condition

// Otherwise credit score is less than 700
else
{
// Assigns the 6 index position data to rate
rate = rateInterest[6];
cout << "Your interest rate is " <<rate<<"%"<< endl;
}

// Calculation
rate /= NUMBER_OF_MONTHS;

rate /= HUNDRED; // 4.25% == .0425

// Payment = [Rate * (1 + Rate)^(loanLength*12) / ((1 + Rate)^(loanLength*12) - 1)] * loanAmnt
payment = ((rate)*pow(ONE + (rate), (loanLength * 12)) / (pow(ONE + (rate), (loanLength * 12)) - ONE)) * loanAmnt;

rate *= HUNDRED; // .0425 == 4.25

totalPaid = (loanLength * 12) * payment;

interestPaid = ((loanLength * 12) * payment) - loanAmnt;

// Display information to user
cout << setprecision(2) << fixed << right << endl;

cout << "Loan Amount: $";
cout << setw(10) << loanAmnt << endl;

cout << "Monthly Interest Rate: ";
cout << setw(10) << rate << '%' << endl;

cout << "Number of Payments: ";
cout << setw(10) << (loanLength * 12) << endl;

cout << "Monthly Payment: $";
cout << setw(10) << payment << endl;

cout << "Total Amount Paid: $";
cout << setw(10) << totalPaid << endl;

cout << "Interest Paid: $";
cout << setw(10) << interestPaid;
return 0;
}// End of main function

Sample Output:

Mortgage Calculator


What is the Amount of the loan? 5000
What is your credit score? 900
Mortgage Period (Years)? 2
Your interest rate is 2.8%

Loan Amount: $ 5000.00
Monthly Interest Rate: 0.23%
Number of Payments: 24
Monthly Payment: $ 214.47
Total Amount Paid: $ 5147.24
Interest Paid: $ 147.24

Add a comment
Know the answer?
Add Answer to:
I've created a mortgage calculator and the next step in my project is to include an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is my code for a final GPA calculator. For this assignment, I'm not supposed to...

    This is my code for a final GPA calculator. For this assignment, I'm not supposed to use global variables. My question is: does my code contain a global variable/ global function, and if so how can I re-write it to not contain one? /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * Title: Final GPA Calculator * Course Computational Problem Solving CPET-121 * Developer: Elliot Tindall * Date: Feb 3, 2020 * Description: This code takes grades that are input by the student and displays * their...

  • fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string>...

    fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str;    while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title);    getline(inFile, books[size].Author); getline(inFile, books[size].publisher);          getline(inFile,...

  • Can you fix this program and run an output for me. I'm using C++ #include using...

    Can you fix this program and run an output for me. I'm using C++ #include using namespace std; //function to calculate number of unique digit in a number and retun it int countUniqueDigit(int input) {    int uniqueDigitCount = 0;    int storeDigit = 0;    int digit = 0;    while (input > 0) {        digit = 1 << (input % 10);        if (!(storeDigit & digit)) {            storeDigit |= digit;       ...

  • I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for.....

    I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for..while..do while,loops,pointer,address,continue,return,break. Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols !.@,#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The...

  •    moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring>...

       moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring> using namespace std; typedef struct{ int id; char title[250]; int year; char rating[6]; int totalCopies; int rentedCopies; }movie; int loadData(ifstream &infile, movie movies[]); void printAll(movie movies[], int count); void printRated(movie movies[], int count); void printTitled(movie movies[], int count); void addMovie(movie movies[],int &count); void returnMovie(movie movies[],int count); void rentMovie(movie movies[],int count); void saveToFile(movie movies[], int count, char *filename); void printMovie(movie &m); int find(movie movies[], int...

  • Use this code to create multiple functions. #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() {...

    Use this code to create multiple functions. #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { cout << fixed << showpoint << setprecision(2); ofstream outFile; outFile.open("Feras's.txt"); outFile << "..Skinny Feras's Restaurant ..\n\n" << endl; int choise=10, quantity; float paid, SubTotal=0, Tax = .10, Total, RM, more; while(choise!=0) { system("cls"); cout << "\t**Welcome To Skinny Alsaif Restaurant Lol**" << endl; cout << "\nWhat would you like to have?" << endl; cout << "1. Burger." << endl; cout << "2. Pizza." <<...

  • Hello, I am trying to get this Array to show the summary of NETPAY but have...

    Hello, I am trying to get this Array to show the summary of NETPAY but have been failing. What is wrong? #include <iostream> #include <iomanip> using namespace std; main(){ char empid[ 100 ][ 12 ];    char fname[ 100 ][ 14 ], lastname[ 100 ][ 15 ];    int sum; int hw[ 100 ]; double gp[ 100 ], np[ 100 ], hr[ 100 ], taxrate[100], taxamt[ 100 ]; int counter = 0; int i; cout<<"ENTER EMP ID, FNAME, LNAME, HRS...

  • Rework this project to include a class. As explained in class, your project should have its...

    Rework this project to include a class. As explained in class, your project should have its functionalities moved to a class, and then create each course as an object to a class that inherits all the different functionalities of the class. You createclass function should be used as a constructor that takes in the name of the file containing the student list. (This way different objects are created with different class list files.) Here is the code I need you...

  • Here are the files I've made so far: /********************* * File: check05b.cpp *********************/ #include &lt...

    Here are the files I've made so far: /********************* * File: check05b.cpp *********************/ #include <iostream> using namespace std; #include "money.h" /**************************************************************** * Function: main * Purpose: Test the money class ****************************************************************/ int main() {    int dollars;    int cents;    cout << "Dollar amount: ";    cin >> dollars;    cout << "Cents amount: ";    cin >> cents;    Money m1;    Money m2(dollars);    Money m3(dollars, cents);    cout << "Default constructor: ";    m1.display();    cout << endl;    cout << "Non-default constructor 1: ";    m2.display();    cout << endl;   ...

  • I know I'm on the right path, but don't know where to continue from here. This is a C++ assignmen...

    I know I'm on the right path, but don't know where to continue from here. This is a C++ assignment Your job is to write that will display a calendar for any given month of a given year. The user will need to type the number of the month as an integer from 1 to 12 (1 is for January, etc.), and the year as a 4-digit integer. This assignment simply requires that your program make use of more than...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT