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.