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");
}
#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
I've created a mortgage calculator and the next step in my project is to include an...
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...
1.- i need help with my code because it appears me "main.cpp:77:7: error: expected unqualified-id before ‘else’ else (s == 't' || s == 'T' || s == '3') ^~~~" #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { double l1, l2, bl, h, d, l, p, a, h1, h2, el, ia,sb,sh,P,A,oa,pc ; double ap,pp,shp,cl,bsp,iap,blp,elp,o; char s; double const pi = 3.14159265; cout <<setfill('*')<<setw(36)<<'*'<<endl; cout <<setw(1)<<'*'<<" Rebel Alliance Computation Support "<<endl; cout <<setw(1)<<'*'<<" Star area calculator "<<endl;...
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,...
How do I get this code to output The monthly payment is too low resulting in the loan amount not being able to be repaid, if the monthly payment is not higher than the interest rate. Right now I cant get it to say that. #include <iostream> using namespace std; int main() { double monthlyPayment; double remainingBalance; double interestRate; int month = 1; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << "Enter loan amount: $";...
#include <iostream> #include <cmath> #include <iomanip> #include <cstdlib> using namespace std; bool isInt (double value) { double dummy; return bool(modf(value, &dummy) == 0); } double sqr(double value) { return value * value; } double calcFrictionFactor(double R, double D, double epsilon) { const double BlasiusCoefficient = 0.3164; double f_old, f_new; f_new = BlasiusCoefficient * pow(R, -0.25); // loop until our two values are within 0.000001 of each other do { f_old = f_new; // previous guess is now the old one...
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..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>
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()
{
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 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...