I am making a calculator, for operations such as addition I used code as
if ([operand isEqualToString:@"+"])
lastKnownValue += currentValue;
Which means that if the plus button is tapped, to the number the user specified before that, the number specified after is added.
Pretty much same works with division, by using
/=
And so on.
But how can I make it calculate the first number to the power of the second?
Or calculate the root (with the base of the second number) of the first number?
You can compute a power using the
powfunction:The y’th root of x is the same as x to the 1/y power: