Mortgage Payment Using Classes

Hey, how's everyone doing today? Well I have this project due and I'm absolutely stuck on this. Basically, this program is designed to use classes to calculate monthly mortgage payments. What I'm confused about is the getFunctions to calculate the actual information. Here's what I've got so far:

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
#include <iomanip>
#include <iostream>
#include <cmath>

using namespace std;

class MortgagePayment
{
	private: 
			  double payment, loan, rate, total;
			  int years;
	
	public:
			  void setLoan(double);
			  void setRate(double);
			  void setYears(int);
			  double getMonthlyPayment(double);
			  double getTotalPay();
};

//Set Methods
void MortgagePayment::setLoan(double L)
{
	loan = L;
}

void MortgagePayment::setRate(double R)
{
	rate = R;
}

void MortgagePayment::setYears(int Y)
{
	years = Y;
}

double MortgagePayment::getMonthlyPayment(double Term)
{
	return payment = ( loan * rate/12 * Term ) / (Term-1);
}

double MortgagePayment::getTotalPay()
{
	return total = payment * years;
}

int main()
{
	MortgagePayment mortgage1;
	MortgagePayment mortgage2;
	MortgagePayment mortgage3;
	
	int choice;
	double Term;
	double LoanInput;
	double RateInput;
	double YearsInput;
	
	//Front Intro Page
	cout << "\n\n\t\t    ********************************\n"
	 	  << "\n\t\t\t  CIS 180 Honors Work\n\n\t\t\t  Mortgage Payment\n"
	     << "\n\t\t\t\t By \n\n\t\t\t   Trevor Davenport"
	     << "\n\n\t\t    ********************************\n\n\n"
		  << "DESCRIPTION: This Program Demonstrates The Usage Of Classes,\n"
		  << "\t     Calculates The Total Monthly Payment For Mortgages,\n"
		  << "\t     Calculates The Total Amount Paid To The Banks,\n"
		  << "\t     And Returns The Above Mentioned In A Output Report.\n\n";
		  system("pause");
		  system("cls");
		  
	cout << "\n\nMORTGAGE PAYMENT OPTIONS:\n\n\tOption 1\n\n \tLoan Amount - $5,000.00\n\tRate - 5.0%\n\tYears - 5"
		  << "\n\n\tOption 2\n\n \tLoan Amount - $10,000.00\n\tRate - 4.5%\n\tYears - 7"
		  << "\n\n\tOption 3\n\n \tLoan Amount - $15,000.00\n\tRate - 6.5%\n\tYears - 9"
		  << "\n\n\tWhich Payment Option Would You Prefer? ";
	cin >> choice;
	
	//Input Validation
	while ( choice < 1 || choice > 3 )
	{
		cout << "\n\tError. Invalid Choice, Please Choose Again. ";
		cin >> choice;
	}
	
	system("cls");
	
	switch (choice)
	{
		case 1: mortgage1.setLoan(5000.00);
				  mortgage1.setRate(.05);
				  mortgage1.setYears(5);
				  Term = (1 + .05/12) * pow(12, 5); // Term = ( 1 + Rate / 12 ) ^ 12 * Years
				  break;
		
		case 2: mortgage2.setLoan(10000.00);
				  mortgage2.setRate(.045);
				  mortgage2.setYears(7);
				  Term = (1 + .045/12) * pow(12, 7);
				  break;
		
		case 3: mortgage3.setLoan(15000.00);
				  mortgage3.setRate(.065);
				  mortgage3.setYears(9);
				  Term = (1 + .065/12) * pow(12, 9);
				  break;
				  
	}
	
		if ( choice == 1 )
		{
			cout << "\nMORTGAGE SUMMARY:\n\n\tLoan Amount - $5,000.00\n\tRate - 5.0%\n\tYears - 5\n\tMonthly Payment: " << fixed << setprecision(2) << mortgage1.getMonthlyPayment(Term);
			cout << "\nOTHER OPTIONS INCLUDED:\n\n\tLoan Amount - $10,000.00\n\tRate - 4.5%\n\tYears - 7\n\tMonthly Payment: " << fixed << setprecision(2) << mortgage2.getMonthlyPayment(Term);
			cout << "\nOTHER OPTIONS INCLUDED:\n\n\tLoan Amount - $15,000.00\n\tRate - 6.5%\n\tYears - 9\n\tMonthly Payment: " << fixed << setprecision(2) << mortgage3.getMonthlyPayment(Term);
		}
		
		if ( choice == 2 )
		{
		
		}
		
		if ( choice == 3 ) 
		{
		
		}
		
}


Any criticism and help would be greatly appreciated seeing as this project is due tomorrow. Thanks again.

Trevor
Last edited on
My Errors Are As Follows:

Error E2451 MortagePayment.cpp 39: Undefined symbol 'Loan' in function MortgagePayment::getMonthlyPayment(double,double,double)
Error E2451 MortagePayment.cpp 39: Undefined symbol 'Rate' in function MortgagePayment::getMonthlyPayment(double,double,double)
Error E2451 MortagePayment.cpp 39: Undefined symbol 'Term' in function MortgagePayment::getMonthlyPayment(double,double,double)
Error E2227 MortagePayment.cpp 86: Extra parameter in call to MortgagePayment::setLoan(double) in function main()
Error E2060 MortagePayment.cpp 89: Illegal use of floating point in function main()
Error E2227 MortagePayment.cpp 92: Extra parameter in call to MortgagePayment::setLoan(double) in function main()
Error E2060 MortagePayment.cpp 95: Illegal use of floating point in function main()
Error E2227 MortagePayment.cpp 98: Extra parameter in call to MortgagePayment::setLoan(double) in function main()
Error E2060 MortagePayment.cpp 101: Illegal use of floating point in function main()
For the first 3 ones, variable names are case sensitive
For the other ones, you have to use '.' for the decimal part of a number, but the integer part must not be split by ',', or it is interpreted as 2 expressions
I edited what I had, It was quite a bit off. Could someone let me know how it looks now?
I agree with the term formula in comments, but i don't think you wrote it right. I won't tell you the answer, but look at it again.
I'm not following, I thought the calculation was correct...
The only thing that I can't get to display is the Total Amount Owed to bank from my getTotalPay function. I'm not exactly sure what to pass it.
Topic archived. No new replies allowed.