Mortgage Program

/*University of Phoenix PRG/410
Week 5
Filename: Week 5.cpp
Date: 4/09/2010

Change Order #11
Write the program as a procedural C++ program.
Allow the user to input the amount of a mortgage and then select from a menu of mortgage loans:

- 7 year at 5.35%
- 15 year at 5.5%
- 30 year at 5.75%

Use an array for the different loans.
Display the mortgage payment amount.
Then, list the loan balance and interest paid for each payment over the term of the loan.
On longer-term loans, the list will scroll off the screen.
Do not allow the list to scroll off the screen, but rather display a partial list and then allow the user to continue the list.
Allow the user to loop back and enter new data or quit. Insert comments in the program to document the program.
*/

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

int main(int argc, char *argv[]) // Main, argc and *argv give the number and value of the program arguments in the command line.
{
	//provide program explanation for the user
	cout << "   " << endl;
	cout << "   ///////////////////////////////////////////////////////////////////////////// " << endl;
	cout << "   //                       Mortgage Calculator Program                       // " << endl;
	cout << "   //  Enter the amount of your mortgage and select from three predetermined  // " << endl;
	cout << "   //  loan options.  This program will calculate your monthly payment and    // " << endl;
	cout << "   //  loan amortization. You will have the option of entering new data if    // " << endl;
	cout << "   //  desired or quitting the program without finishing the amortization.    // " << endl;
	cout << "   ///////////////////////////////////////////////////////////////////////////// " << endl;
	cout << "   " << endl << endl << endl << endl << endl << endl;

	double loanAmount;                 // Amount of the Loan
	double monthlyPayment;         // Monthly Payment of the Loan
	double balancePrincipal;           // Balance of the Principal
	double interestPaid;                       // Interest Paid on the Loan
	double principalPaid;             // Amount Paid on the Principal
	double interestRate[3] = {5.25, 5.50, 5.75};  // Array for the Interest Rate of the Loan

	int paymentCountdown;
	int newList = 0;           // Display partial list
	int mortgageTerm[3] = {7, 15, 30}; // Array for the length of the loan

	char continueList;
	char quit;                                 // Prompt user to quit
		quit = 'C';                     // Quit variable

	while (quit != 'Q' && quit != 'q')
	{
		//allow selection of the different mortgage option
		cout << "\t        Enter a numerical value for your loan amount: ";
		cin >> loanAmount;
		cout << "\t        Select mortgageTerm of Loan and Interest Rate  " << endl;
		cout << "\t        1.  7 Years at 5.35% " << endl;
		cout << "\t        2. 15 Years at 5.50% " << endl;
		cout << "\t        3. 30 Years at 5.75% " << endl;
		cout << "\t        Enter Selection Here: (1,2,3)";

		int choice;
		cin >> choice;
		cout << endl << endl << endl;

		// make the bloody array work
		int i;
		for (i = 0; i < 1; i++)
		switch (choice)
		{
			case 0: cout << endl;
			break;
			case 1:
				mortgageTerm[1] = 7;
				interestRate[1] = 5.35;
				cout << "\t        You Selected 7 Years and 5.35%" << endl;
			break;
			case 2:
				mortgageTerm[2] = 15;
				interestRate[2]= 5.50;
				cout << "\t        You Selected 15 Years at 5.50%" << endl;
			break;
			case 3:
				mortgageTerm[3] = 30;
				interestRate[3] = 5.75;
				cout << "\t        You Selected 30 Years at 5.75%" << endl;
			break;
			default:
			cout << "\t        Please select a valid line number" << endl;
		}

		cout << endl;

		//Calculate the monthly payment
		monthlyPayment = loanAmount * (interestRate[choice] / 1200) / (1 - pow(1 + (interestRate[choice] / 1200), - 1 * (mortgageTerm[choice] * 12)));

		cout << "\t        Monthly Payments: $" << monthlyPayment << endl << endl;
		double numPayments = mortgageTerm[choice] * 12;
		newList = 0;

		//Enter amortization loop
		for (paymentCountdown = 1; paymentCountdown <= numPayments; ++paymentCountdown)
		{
			// Calculations to determine balance and interest
			interestPaid = loanAmount * (interestRate[choice] / 1200);
			principalPaid = monthlyPayment - interestPaid;
			balancePrincipal = loanAmount - principalPaid;

			if (balancePrincipal < 0)balancePrincipal = 0;
			loanAmount = balancePrincipal;

			// loop the list to prevent scrolling
			if (newList == 0)
			{
				cout << "\t\tPrincipal Balance" << "\t\tInterest Paid" << endl;
				cout << "\t\t____________" << "\t\t_____________" << endl << endl;
			}

			cout << fixed << showpoint << setprecision(2) // Sets the digits equal to make the output more attractive
			<< "\t\t$" << balancePrincipal
			<< "\t\t$" << interestPaid << endl;
			++newList;

			// Give the user the option to continue the program, enter new data, or quit
			if (newList == 12)
			{
				cout << endl << endl;
				cout << "\tEnter 'C' to Continue, " << "'N' to input a New loan, " << "'Q' to Quit> ";
				cin >> continueList;
				if ((continueList == 'C')||(continueList == 'c'))newList = 0;
				else if ((continueList == 'N')||(continueList == 'n'))
				break; // halt the loop if selected, then restart
				else if ((continueList == 'Q')||(continueList == 'q'))
				return 0; // End Program
			}
		}		

		do                                // validate the user for new data
		{
			cout << "\tEnter 'C' to Continue, 'Q' to Quit> ";
			cin  >> quit;
			cout << "\n";
		}

		while ((quit != 'q') &&
		(quit != 'Q') &&
		(quit != 'c') &&
		(quit != 'C'));
	}

	cout << endl;
	system("PAUSE");
	return EXIT_SUCCESS;             // Quit and exit program
}
/*Jocelyn Williams
University of Phoenix PRG/410
Week 5
Filename: Week 5 – Jocelyn Williams.cpp
Date: 4/09/2010

Change Order #11
Write the program as a procedural C++ program.
Allow the user to input the amount of a mortgage and then select from a menu of mortgage loans:

- 7 year at 5.35%
- 15 year at 5.5%
- 30 year at 5.75%

Use an array for the different loans.
Display the mortgage payment amount.
Then, list the loan balance and interest paid for each payment over the term of the loan.
On longer-term loans, the list will scroll off the screen.
Do not allow the list to scroll off the screen, but rather display a partial list and then allow the user to continue the list.
Allow the user to loop back and enter new data or quit. Insert comments in the program to document the program.
*/

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

int main(int argc, char *argv[]) // Main, argc and *argv give the number and value of the program arguments in the command line.
{
//provide program explanation for the user
cout << ” ” << endl;
cout << ” ///////////////////////////////////////////////////////////////////////////// ” << endl;
cout << ” // Mortgage Calculator Program // ” << endl;
cout << ” // Enter the amount of your mortgage and select from three predetermined // ” << endl;
cout << ” // loan options. This program will calculate your monthly payment and // ” << endl;
cout << ” // loan amortization. You will have the option of entering new data if // ” << endl;
cout << ” // desired or quitting the program without finishing the amortization. // ” << endl;
cout << ” ///////////////////////////////////////////////////////////////////////////// ” << endl;
cout << ” ” << endl << endl << endl << endl << endl << endl;

double loanAmount; // Amount of the Loan
double monthlyPayment; // Monthly Payment of the Loan
double balancePrincipal; // Balance of the Principal
double interestPaid; // Interest Paid on the Loan
double principalPaid; // Amount Paid on the Principal
double interestRate[3] = {5.25, 5.50, 5.75}; // Array for the Interest Rate of the Loan

int paymentCountdown;
int newList = 0; // Display partial list
int mortgageTerm[3] = {7, 15, 30}; // Array for the length of the loan

char continueList;
char quit; // Prompt user to quit
quit = ‘C’; // Quit variable

while (quit != ‘Q’ && quit != ‘q’)
{
//allow selection of the different mortgage option
cout << “\t Enter a numerical value for your loan amount: “;
cin >> loanAmount;
cout << “\t Select mortgageTerm of Loan and Interest Rate ” << endl;
cout << “\t 1. 7 Years at 5.35% ” << endl;
cout << “\t 2. 15 Years at 5.50% ” << endl;
cout << “\t 3. 30 Years at 5.75% ” << endl;
cout << “\t Enter Selection Here: (1,2,3)”;

int choice;
cin >> choice;
cout << endl << endl << endl;

// make the bloody array work
int i;
for (i = 0; i < 1; i++)
switch (choice)
{
case 0: cout << endl;
break;
case 1:
mortgageTerm[1] = 7;
interestRate[1] = 5.35;
cout << “\t You Selected 7 Years and 5.35%” << endl;
break;
case 2:
mortgageTerm[2] = 15;
interestRate[2]= 5.50;
cout << “\t You Selected 15 Years at 5.50%” << endl;
break;
case 3:
mortgageTerm[3] = 30;
interestRate[3] = 5.75;
cout << “\t You Selected 30 Years at 5.75%” << endl;
break;
default:
cout << “\t Please select a valid line number” << endl;
}

cout << endl;

//Calculate the monthly payment
monthlyPayment = loanAmount * (interestRate[choice] / 1200) / (1 – pow(1 + (interestRate[choice] / 1200), – 1 * (mortgageTerm[choice] * 12)));

cout << “\t Monthly Payments: $” << monthlyPayment << endl << endl;
double numPayments = mortgageTerm[choice] * 12;
newList = 0;

//Enter amortization loop
for (paymentCountdown = 1; paymentCountdown <= numPayments; ++paymentCountdown)
{
// Calculations to determine balance and interest
interestPaid = loanAmount * (interestRate[choice] / 1200);
principalPaid = monthlyPayment – interestPaid;
balancePrincipal = loanAmount – principalPaid;

if (balancePrincipal < 0)balancePrincipal = 0;
loanAmount = balancePrincipal;

// loop the list to prevent scrolling
if (newList == 0)
{
cout << “\t\tPrincipal Balance” << “\t\tInterest Paid” << endl;
cout << “\t\t____________” << “\t\t_____________” << endl << endl;
}

cout << fixed << showpoint << setprecision(2) // Sets the digits equal to make the output more attractive
<< “\t\t$” << balancePrincipal
<< “\t\t$” << interestPaid << endl;
++newList;

// Give the user the option to continue the program, enter new data, or quit
if (newList == 12)
{
cout << endl << endl;
cout << “\tEnter ‘C’ to Continue, ” << “‘N’ to input a New loan, ” << “‘Q’ to Quit> “;
cin >> continueList;
if ((continueList == ‘C’)||(continueList == ‘c’))newList = 0;
else if ((continueList == ‘N’)||(continueList == ‘n’))
break; // halt the loop if selected, then restart
else if ((continueList == ‘Q’)||(continueList == ‘q’))
return 0; // End Program
}
}

do // validate the user for new data
{
cout << “\tEnter ‘C’ to Continue, ‘Q’ to Quit> “;
cin >> quit;
cout << “\n”;
}

while ((quit != ‘q’) &&
(quit != ‘Q’) &&
(quit != ‘c’) &&
(quit != ‘C’));
}

cout << endl;
system(“PAUSE”);
return EXIT_SUCCESS; // Quit and exit program
}

© 2010, Within this mind. All rights reserved.

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • Blogosphere
  • Fark
  • Google Buzz
  • LinkedIn
  • Reddit
  • Slashdot
  • Suggest to Techmeme via Twitter

About Kinda Strange

I am a student at the University of Phoenix majoring in information technology. This is where I come to babble incoherently…err…make notes, talk about things that catch my interest, share ideas, etc...
This entry was posted in Homework and tagged . Bookmark the permalink.

2 Responses to Mortgage Program

  1. HusinhandzalahNo Gravatar says:

    why this programme can’t be run???

  2. Kinda StrangeNo Gravatar says:

    Because the fourth time someone copy-pasted this post and turned it in as their homework at UoP, I altered it. Call it schmuck bait.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>