1. ## newbie question

This is a two part question: 1st, How do I use a negative value in an equation? I tried just putting a "-" in front of the number, but my calculations are not coming out correctly. 2nd, My error could be related to "pow"... I am using an equation for each argument, and I'm wondering if that might be what is throwing the whole thing off... Any help would be greatly appreciated!!! Thank you!!

okay, here's the code:
Code:
```{

float L;                                                        //amount of loan
float R;                                                        //annual interest rate
float r = (R * 0.01) / 12;                                      //monthly interest rate
int i;                                                          //length of loan in years
double P = L * (r / 1 - pow( (1 + r), (-i * 12) ) );              //monthly payment
double total = P * (i * 12);                                    //total amount paid to bank

cout << setw(7);
cout << setiosflags(ios::fixed | ios::showpoint);
cout << setprecision(2);
cout << "\nEnter the loan amount: ";
cin >> L;
cout << "\nEnter the annual interest rate: ";
cin >> R;
cout << "\nEnter the length of the loan in years: ";
cin >> i;

cout << "\n\nLoan: \$" << L << endl;
cout << "Interest-rate: " << R << " %\n";
cout << "Years: " << i << endl;
cout << "Monthly Payment: \$" << P << endl;
cout << "\nTotal-paid: \$" << total << endl;
}```

2. ## edited original post to include code...

Thanks for checking out my question. I edited my first post and included the code...

3. You are trying to initialise variables with other variables who's value you have not read yet, thus they maybe zero, or rubbish depending on your compiler. Instead of...
Code:
```{

float L;                                                        //amount of loan
float R;                                                        //annual interest rate
float r = (R * 0.01) / 12;                                      //monthly interest rate
int i;                                                          //length of loan in years
double P = L * (r / 1 - pow( (1 + r), (-i * 12) ) );              //monthly payment
double total = P * (i * 12);                                    //total amount paid to bank

cout << setw(7);
cout << setiosflags(ios::fixed | ios::showpoint);
cout << setprecision(2);
cout << "\nEnter the loan amount: ";
cin >> L;
cout << "\nEnter the annual interest rate: ";
cin >> R;
cout << "\nEnter the length of the loan in years: ";
cin >> i;

cout << "\n\nLoan: \$" << L << endl;
cout << "Interest-rate: " << R << " %\n";
cout << "Years: " << i << endl;
cout << "Monthly Payment: \$" << P << endl;
cout << "\nTotal-paid: \$" << total << endl;
}```
... use...
Code:
```{

float L;                                                        //amount of loan
float R;                                                        //annual interest rate
float r;                    //monthly interest rate
int i;                                                          //length of loan in years
double P = L * (r / 1 - pow( (1 + r), (-i * 12) ) );              //monthly payment
double total = P * (i * 12);                                    //total amount paid to bank

cout << setw(7);
cout << setiosflags(ios::fixed | ios::showpoint);
cout << setprecision(2);
cout << "\nEnter the loan amount: ";
cin >> L;
cout << "\nEnter the annual interest rate: ";
cin >> R;

r = (R * 0.01) / 12;

cout << "\nEnter the length of the loan in years: ";
cin >> i;

cout << "\n\nLoan: \$" << L << endl;
cout << "Interest-rate: " << R << " %\n";
cout << "Years: " << i << endl;
cout << "Monthly Payment: \$" << P << endl;
cout << "\nTotal-paid: \$" << total << endl;
}```
... for example. There are others.

4. Thanks Adrian! I moved the variables r, P, and total down after the input, and the output is much better! Now I just have to figure out what I did wrong with my equation because even though the result finally shows up as a value, it's not the correct value...

here's the updated code: (I'm working on simplifying the equation)
Code:
```{

float L;								//amount of loan
float R;								//annual interest rate
int i;								//length of loan in years

cout << setw(7);
cout << setiosflags(ios::fixed | ios::showpoint);
cout << setprecision(2);
cout << "\nEnter the loan amount: ";
cin >> L;
cout << "\nEnter the annual interest rate: ";
cin >> R;
cout << "\nEnter the length of the loan in years: ";
cin >> i;

int m = i * 12;							//calculates length of loan in months
float r = (R * 0.01) / 12;					//calculates monthly interest rate
double P = (r / 1 - pow( ++r, -m ) ) * L;			//calculates monthly payment
double total = P * (i * 12);					//calculates total amount paid to bank

cout << "\n\nLoan: \$" << L << endl;
cout << "Interest-rate: " << R << " %\n";
cout << "Years: " << i << endl;
cout << "Monthly Payment: \$" << P << endl;
cout << "\nTotal-paid: \$" << total << endl;

}```

5. ## update: it's fixed!! :D

I finally figured out what was wrong... I just broke down the equation into smaller parts. It's working great!! Thank you!