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
|
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>
#include <cmath>
#include <math.h>
using namespace std;
#define PROPERTY_TAX 0.0125
#define UTILITIES 300.00
#define INSURANCE 550.00
// Function Prototypes
void input(double& sellingPrice, double& annualROI, double& numberOfYears);
double calc(double sellingPrice, double numberOfYears, double annualROI, double downPayment, double& DP, double& MP, double& amountOfLoan);
void subfunc(double& DP, double& amountOfLoan, double& MP, double sellingPrice, double rateOfInterest, double numOfCompPer);
void output(double sellingPrice, double DP, double amountOfLoan, double annualROI, double numberOfYears, double MP, double total);
void signature();
int main()
{
double sellingPrice, annualROI, numberOfYears, DP = 0.0, amountOfLoan = 0.0, MP = 0.0, downPayment = 0.0, total = 0.0;
input(sellingPrice, annualROI, numberOfYears);
calc(sellingPrice, numberOfYears, annualROI, downPayment, DP, MP, amountOfLoan);
total = calc(sellingPrice, numberOfYears, annualROI, downPayment, DP, MP, amountOfLoan);
output(sellingPrice, DP, amountOfLoan, annualROI, numberOfYears, MP, total);
system("pause");
return 0;
}
void input(double& sellingPrice, double& annualROI, double& numberOfYears)
{
cout << "Selling Price: $";
cin >> sellingPrice;
cout << "Rate of Interest: ";
cin >> annualROI;
cout << "Number Of Years for Loan: ";
cin >> numberOfYears;
cout << endl;
return;
}
double calc(double sellingPrice, double numberOfYears, double annualROI, double downPayment, double& DP, double& MP, double& amountOfLoan)
{
//calc2(sellingPrice, downPayment, numberOfYears)
double rateOfInterest, numOfCompPer, total;
rateOfInterest = (annualROI * .01) / 12;
numOfCompPer = numberOfYears * 12;
subfunc(DP, amountOfLoan, MP, sellingPrice, rateOfInterest, numOfCompPer);
total = MP + UTILITIES + ((PROPERTY_TAX * sellingPrice) / (12 * numberOfYears)) + ((INSURANCE * numberOfYears) / (12 * numberOfYears));
return total;
}
// return total
void subfunc(double& DP, double& amountOfLoan, double& MP, double sellingPrice, double rateOfInterest, double numOfCompPer)
{
const double downPayment = 0.20;
DP = (downPayment * sellingPrice);
amountOfLoan = sellingPrice - DP;
MP = (amountOfLoan * rateOfInterest * pow((1 + numOfCompPer), numOfCompPer)) / (pow((1 + numOfCompPer), numOfCompPer - 1));
}
void output(double sellingPrice, double DP, double amountOfLoan, double annualROI, double numberOfYears, double MP, double total)
{
cout << setprecision(2) << fixed << setw(9) << left << "Monthly Cost Of House" << endl;
cout << setprecision(2) << fixed << setw(9) << left << "Selling Price:" << setw(15) << right << "$" << right << sellingPrice << endl;
cout << setprecision(2) << fixed << setw(20) << left << "Down Payment:" << setw(18) << right << DP << endl;
cout << setprecision(2) << fixed << setw(20) << left << "Amount Of Loan:" << setw(18) << right << amountOfLoan << endl;
cout << setprecision(2) << fixed << setw(20) << left << "Interest Rate:" << setw(17) << right << annualROI * 0.01 << "%" << endl;
cout << setprecision(2) << fixed << setw(20) << left << "Tax Rate:" << setw(17) << right << PROPERTY_TAX * 100 << "%" << endl;
cout << setprecision(0) << fixed << setw(20) << left << "Duration of Loan (years):" << setw(13) << right << numberOfYears << endl << endl;
cout << setprecision(2) << fixed << setw(20) << left << " ==== Monthly Payment ====" << endl << endl;
cout << setprecision(2) << fixed << setw(20) << left << " Mortgage:" << setw(18) << right << MP << endl;
cout << setprecision(2) << fixed << setw(20) << left << " Utilities:" << setw(18) << right << UTILITIES << endl;
cout << setprecision(2) << fixed << setw(20) << left << " Property Taxes:" << setw(18) << right << (PROPERTY_TAX * sellingPrice) / (12 * numberOfYears) << endl;
cout << setprecision(2) << fixed << setw(20) << left << " Insurance:" << setw(18) << right << (INSURANCE * numberOfYears) / (12 * numberOfYears) << endl;
cout << setprecision(2) << fixed << setw(39) << right << "---------" << endl;
cout << setprecision(2) << fixed << setw(20) << left << " Total:" << setw(18) << right << total << endl << endl;
signature();
}
|