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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153

//Shelby Teele
//steele@cnm.edu
//STeeleP4
#include <iostream>
#include <string>
#include "MortCalc.h"
using namespace std;
int main()
{
string answer;
Header();
do
{
double principal = 0;
double interest = 0;
int years = 0;
AskForPrin();
AskInterest();
AskYears();
bool validate = ValidateNums(principal, interest, years);
if(validate == true)
{
Calculation(principal, interest, years);
}
else
{
cout << "Sorry, that information is not usable.\n"
<< "Please enter another.\n";
}
cout << "Would you like to calculate another mortgage? y or n\n";
cin>>answer;
}while(answer == "y");
cout << "Thank you for using the Mortgage Calculator! Goodbye!\n";
return 0;
}
//This is the driver.
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include "MortCalc.h"
using namespace std;
void Header()
{
cout << "My name is Shelby Teele.\n"
<< "Welcome to the C++ Mortgage Calculator!\n"
<< "This program will help calculate your monthly mortgage\n"
<<"payment.\n";
}
double AskForPrin()
{
double principal = 0;
cout << "How much are you borrowing?\n"
<< "Please, no more than $500,000.\n";
cin>> principal;
return principal;
}
double AskInterest()
{
double interest =0;
cout << "What is your monthly interest rate?\n"
<<"Please enter single digits, such as 5,\n"
<<"for the interest rate, no more than 10.\n";
cin >> interest;cout <<"%\n";
return interest;
}
int AskYears()
{
int years = 0;
cout << "How many years would you like to borrow for?\n"
<< "15, 25, or 30?\n";
cin>> years;
return years;
}
bool ValidateNums(double principal, double interest, int years)
{
bool validate = true; //This is that tricky bool
if(principal <=0  principal > 500000)
{
validate= false;
}
if(interest > 0.00  interest <= 10.00)
{
validate = true;
}
if(years != 15  years != 25  years != 30)
{
validate = false;
}
return validate;
}
string Calculation(double principal, double interest, int years)
{
int q = 12;
double i = interest/100.00;
double p = principal;
int n = years;
int x = (n*q);
double y = 1 +(i/q);
double z = pow(y, x);
double monthlyPayment = (p*i)/q*(1z);
double totalAmountPaid = monthlyPayment * (n*q);
double totalInterest = totalAmountPaid  p;
stringstream ss;
ss <<"Your monthly payment is: $" <<monthlyPayment<<".\n"
<<"The total amount you have payed over the life\n"
<<"of the loan is: $"<<totalAmountPaid<<".\n"
<<"The total amount of the interest paid is: $\n"
<<totalInterest<<".\n";
ss.setf(ios::fixed);
ss.precision(2);
string MortCalc = ss.str();
return MortCalc;
}
//This is all of the functions and calculations.
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;
void Header();
double AskForPrin();
double AskInterest();
int AskYears();
bool ValidateNums(double principal, double interest,int years);
string Calculation(double principal, double interest, int years);
//and this is from my .h file.
 