I’m trying to get this expression to work, I’m pretty sure its not the parenthesis because I counted all of them. Perhaps there something I’m doing wrong involving the parameter pow (x,y).
double calculatePeriodicPayment()
{
periodicPaymentcalc = (loan * ((interestRate / yearlyPayment))) / (1-((pow ((1+(interestRate / yearlyPayment)))),(-(yearlyPayment * numOfYearLoan))));
return periodicPaymentcalc;
}
Notice how much easier it is to figure out what the function is doing if you break each step up into pieces:
(I find it even easier if your variables match the source material, so I’ll name my variables after the ones Wikipedia uses.)
It’s much easier to confirm that the logic of this function does what it should this way.
If you’re curious, substituting my variable names in, your parenthises problem is as follows:
With this grouping, you’re only passing one argument to
pow, which is why the compiler saysno overloaded function takes 1 arguments.Edit: You mentioned I used more variables. However, your compiler will use temporary variables much like I did. Your complex statement will be broken up into pieces, and may look something like this:
Mine will also be broken up, and will look like:
Perhaps there are some optimizations that the compiler will use, such as noticing that it uses
interestRate / yearlyPaymenttwice in your function, and use the same temporary for both places, but there’s no gurantee this will happen. Notice that we use pretty much the same number of variables in both of our functions. I just used more named variables, and fewer unnamed temporaries.