Reputation: 425
m having trouble with the pow function. The equation is A=P*((1+R)/T)^T
were "^" is to the power of. How would i use the pow function, i only see examples that are 4 to the 5th power, nothing like what i have to do
Upvotes: 1
Views: 456
Reputation: 373102
The C++ function std::pow
can be used as follows: if you write
std::pow(base, exponent)
the function computes baseexponent
. In your case, because you want to compute
A = P * ((1 + R) / T) ^ T
You might call the function like this:
A = P * std::pow((1 + R) / T, T);
Note that the second argument needn't be a constant; it can be any value that you'd like, even one you don't know until runtime.
Hope this helps!
Upvotes: 2
Reputation: 882386
Either:
A = P * pow ((1 + R) / T, T)
or:
A = pow (P * (1 + R) / T, T)
depending on whether the power should include the multiplication by P
or not.
I would suspect the former since exponentiation tends to have a higher priority in maths - i.e., 4x2
is 4(x2)
, not (4x)2
.
Upvotes: 0
Reputation: 124770
P * pow((1+R)/T, T)
The second argument is the exponent (power) to raise the first argument to.
Upvotes: 1