Hi All,

I'm new to C++ and I have a C++ mortgage assignment due where a user inputs there mortgage amount, interest rate, and term of the loan and the program should give the user there monthly payment and also ask the user if they want to quit or enter a new amount. However, I've been working on this for two days now but I'm having some trouble with my formula everything is compiling but when the user enters there information there monthly payment result is coming out with 1.#INF. I don't know where I'm going wrong so here is a copy of what I have. Any help will be appreciated.

//Lakesha Conaler
//Week 3 Individual Assignment
#include <math.h>
#include <iostream>
using namespace std;
int main ()
int l = 0; //amount of loan
double i = 0; //interest rate
int y = 0; // loan term
float j = i/(12.0 * 100.0); //Calculates the Interest
int m =y*12; //Number of months
int quit = 1; // decides if user wants to quit
double loanpay; //outputs users loan amount
cout << "Input the total loan amount:\n";
cin >> l;
cout << "Input your interest rate:\n";
cin >> i;
cout << "Input your number of years:\n";
cin >> y;

j = i/(12.0*100.0);
loanpay = (l * i) / (1 - pow((1+i),-m));

cout << "Your monthly payment is: $"<< loanpay<<"\n";
cout << "To Enter a new Loan Amount press 1 or 2 to quit\n";
cin >> quit;
} while (quit==1);
return 0;
10 Years
Discussion Span
Last Post by lballans

You are not doing the calculation for m after getting the value for y from the user.Put m =y*12; after the cin >> y; part.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.