if statement with long equation issue

1
2
3
4
5
6
7
 if (monthlyPayment <(loanAmount * monthlyRate *(pow ((1 + monthlyRate) , desiredYears))) / ((pow ((1 + monthlyRate) , desiredYears))  - 1)) 
        {    
             cout << "You won't pay your loan off within " << desiredYears << " years if you choose that payment."<< endl; 
             cout << "The minimum monthly payment needed to pay off loan in " << desiredYears << " years is $"; 
             cout <<(loanAmount * monthlyRate *(pow ((1 + monthlyRate) , desiredYears))) << endl;              
        }       
             


Even if the monthlyPayment input is higher than the number computed in this formula, this if statement executes. Anyone have any clue why? thanks!
Are you sure it is higher?
replace line 1 with
1
2
3
double tmp =  loanAmount * monthlyRate *pow (1 + monthlyRate , desiredYears) / (pow (1 + monthlyRate , desiredYears)  - 1);//you don't need all those parentheses
cout << "input was " << monthlyPayment << " and tmp is " << tmp << '\n';
if(monthlyPayment < tmp) ...
hmm, With your code it is not higher. I guess the formula just doesn't make sense then since it is supposed to calculate the minimum payment to make in order to have the loan repaid before a certain period of time. with my last input, the loan would be paid off in 3 years but tmp( desired payment to make in order to have loan paid off in a certain period of time) was higher than my input and thus said the loan would not be paid off within the desired amount of time. (which was higher than 3 years.)
Topic archived. No new replies allowed.