I have a constructor that returns the result of two ints with a 'to the power of' operator. I am trying to use the math.pow method to do this but im not to sure how it work.
Here is my constructor
public int Power (int firstNumber, int secondNumber)
{
result = Math.Pow(firstNumber, secondNumber);
return result;
}
and the code that calls it
case "^":
result = application.Power(firstInt, secondInt);
labelResult.Text = ("" + result);
break;
How do i use the Math.Pow method in this situation?
As far as the error you're getting:
Math.Pow takes 2 doubles as arguments and returns a double. Your method is declared as returning an int. This means that result is an int. You need to cast the result of Math.Pow to int:
result = (int)Math.Pow(firstNumber, secondNumber);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments