Sober_Samuel
Sober_Samuel

Reputation: 37

How to raise a number to an absolute value of another number in C#?

My problem is that I need to write a complex mathematical equation which has me raise x to the power of |y|, both numbers entered by user. I've tried using the code below, but it produces a CS7036 error:

There is no argument given that corresponds to the required formal parameter 'y' of 'Math.Pow(double, double)'

class Program
{
    static void Main(string[] args)
    {
        double x,y,z,v;
        Console.Write("x=");
        double.TryParse(Console.ReadLine(), out x);
        Console.Write("y=");
        double.TryParse(Console.ReadLine(), out y);
        Console.Write("z=");
        double.TryParse(Console.ReadLine(), out z);
        v=(1+Math.Pow(Math.Sin(x+y)))/
            Math.Abs(x-2*y/(1+x*x*y*y))*Math.Pow(x,Math.Abs(y))+
            Math.Pow(Math.Cos(Math.Atan(1/z)),2);
        Console.Write("v="+v);
        Console.ReadKey();
    }
}

Upvotes: 0

Views: 668

Answers (2)

tmaj
tmaj

Reputation: 34957

Update

(After the OP posted the code)

Code

        double x,y,z,v;
        Console.Write("x=");
        double.TryParse(Console.ReadLine(), out x);
        Console.Write("y=");
        double.TryParse(Console.ReadLine(), out y);
        Console.Write("z=");
        double.TryParse(Console.ReadLine(), out z);
        v=(1+Math.Pow(Math.Sin(x+y)))/
        Math.Abs(x-2*y/(1+x*x*y*y))*Math.Pow(x,Math.Abs(y))+
        Math.Pow(Math.Cos(Math.Atan(1/z)),2);
        Console.Write("v="+v);
        Console.ReadKey();

Error

enter image description here

Error CS7036 There is no argument given that corresponds to the required formal parameter 'y' of 'Math.Pow(double, double)'

Problem

You are calling Math.Pow() with just one parameter: Math.Sin(x + y) and it requires two parameters.

Solution

Check the formula and call the Math.Pow with two parameters, i.e.:

Math.Pow(Math.Sin(x + y), something_here )

Original answer (before OP added the code and error description)

I'm not sure what C7036 is but this snippet outputs 8:

        var x = 2;
        var y = 3;
        var number = Math.Pow(x, Math.Abs(y));
        Console.Write(number);

In this example x and y are ints and number is of type double.

Upvotes: 2

Access Denied
Access Denied

Reputation: 9461

Try to specify second parameter to your Pow:

Math.Pow(Math.Sin(x + y),SECOND)

in

v = (1 + Math.Pow(Math.Sin(x + y))) / 
...

Upvotes: 3

Related Questions