[help] loan program equation

hi guys I'm new to this forum and this is my first post! anyways I'm having a bit of trouble with this equation that calculates how much one can borrow. I don't really know what's going wrong. If anyone can help that'd be great thanks!

//how much money can i borrow
if (choice == "2")
{
cout << fixed << setprecision(2);
//declaring variables
double p = 0.0; //answer, borrowed money
double r = 0.0; //monthly interest rate
double n = 0.0; //number of months you'll be paying
double m = 0.0; // monthly payment
//prompting the user to give us info
cout << "what is the annual interest rate on your loan?: ";
cin >> r;
cout << "what is your monthly payment in dollars?: ";
cin >> m;
cout << "what is the number of months you intend to pay?: ";
cin >> n;

p = (m * pow(1+(r/100/12),n) -1) / (r/100/12) * (pow(1+(r/100/12),n));

cout << "you can borrow " << p << " dollars\n";
}
like I said everything else is fine there is just something wrong with the equation
Are you sure r is monthly interest rate, not yearly? If yes, why divide by 12?
closed account (48T7M4Gy)
Presumably you were given the equation using ordinary algebraic notation and you have translated it to this rather strange concoction which you are not able to do what you want
p = (m * pow(1+(r/100/12),n) -1) / (r/100/12) * (pow(1+(r/100/12),n));

Please show us the original equation.
Topic archived. No new replies allowed.