954,193 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C++ Mortgage Calculations Help!!

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>
usingnamespace 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
do
{
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;
}
lballans
Newbie Poster
2 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

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.

WolfPack
Postaholic
Moderator
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
 

Thanks for your help! I will try what you posted.

lballans
Newbie Poster
2 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You