I have been trying to get this C++ program to work for my class on a mortgage calculator. I am suppose to let the user enter the amounts for the principal, the term, and the interest. Also, I am suppose to let the user decide to do another mortgage or quit the program. I am able to do the part about the loop. Yet, I am getting a weird result for the monthly payment as $-1.#HD. Here is my code so may be some one can find the mistake I made:
// Mortgage Calculator: This program will calculate the monthly payment for a mortgage based upon the
// values for the loan amount, interest rate, and term.
// David Raymore
// POS 440
// Assignment 2
// June 22, 2006
// Barbara Hecker
// header files
#include <iostream>
#include <cmath>
using namespace std;
// declaring variables
float p = 0; /* Loan Amount */
float i = 0; /* Interest Rate APR */
int l = 0; /* Term */
float j = i/(12 * 100); /* Calculate Interest */
int n = l*12; /* Number of months */
double m = 0; /* Monthly Payment */
int choice = 0;
int main ()
{
do
{
cout << "Enter the loan amount: " << endl;
cin >> p;
cout << "Enter term of the loan: " << endl;
cin >> l;
cout << "The interest rate is: " << endl;
cin >> i;
// Calculating the mortgage using this formula
m = (p*j)/(1-pow((1+j),-n));
cout << "The monthly payment is: $" << m << endl;
cout << "Enter 1 to enter new values for another calculation or enter 2 to quit" << endl;
cin >> choice;
}while (choice==1);
return 0;
}
Sincerely,
David Raymore