problem with mortgage formula

this is the formula ive been using LoanPayment=(loan*intRate/1200)/(1-pow((1+intRate),-month));

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

using namespace std;

int main()
		
	// ** Monthly Payment ** //
{
	system ("color f5");
	string ans,name;
	int menu;
	
	double loan;
	double intRate;
	double month;
	double LoanPayment;
	
	
	cout <<" This program is to calculate the monthly payments"
	<< endl << " of a Loan";
	cout << "\n\n" << endl;
	cout << "-- MENU --" << endl;

	do
	{
		cout << "[1] - Exit" << endl;
		cout << "[2] - calculate the monthly payment of a loan" << endl;
		cout << "[3] - find out if you qualify for a loan" << endl;
		cout << "Option: ";
		cin >> menu;
		

	if ( menu == 2)
	{
		cout << " Enter the Amount: ";
		cin >> loan; // I entered 100,000
		cout << " Enter percentage of interest: ";
		cin >> intRate; // 5 percent

		cout << " Enter the number of months: ";
		cin >> month; // 12 months
		
		

		LoanPayment=(loan*intRate/1200)/(1-pow((1+intRate),-month)); 
	

		


		
       
		cout << " The monthly loan is: " << LoanPayment << endl; // it gives me 416.667 when it should give me 8560.74
    }
	else if (menu == 3 )
	{
		cout << " Enter the amount that you are going to pay monthly ";
		cout << " Enter loan interest";
		cout << " Enter the number of months you're going to pay :";
		cout << " loan amount is: ";

	}
	else if( menu == 1)
	{
		cout << "Invalid Opcion.Please Select 1,2,3";
		cout << "\n" << endl;
	}

	else
	{
		cout << " Are you sure you want to exit the program (y/n) : " ;
		cin >> ans;
		cout << endl;
	}
	
    } while (ans != "y" && ans != "Y");

	return 0;
}
Last edited on
Well, looking at your formula... why is there a comma in it?
@Ispil

pow takes 2 arguments.

@Kb wireless

What is your problem? Does it compile - if not post the compilation errors in full. If it does, then try using the debugger.

I personally hate dislike constructs like what you have on line 79 & do loops (not a big fan of them either).

They are just ugly & not scalable.

You can make use of the toupper function, so you don't have to make 2 tests of the variable.

IMO, a better way is to have a while loop controlled by a bool:

1
2
3
4
5
6
bool Quit = false;
while (!Quit) {

//user wants to quit
Quit = true;
}


The menu should be processed with a switch inside the loop shown above. Always include a default case and remember to put a break statement after each case.

Hope all goes well.
Topic archived. No new replies allowed.