I'm writing a class which should calculate angles (in degrees), after long trying I don't get it to work.

> 
> When r = 45 & h = 0 sum should be around 77,14°
> 
> 
> 

but it returns NaN - Why? I know it must be something with the Math.Atan-Method and a not valid value.

My code:

```
    private int r = 0, h = 0;
    public Schutzwinkelberechnung(int r, int h)
    {
        this.r = r;
        this.h = h;
    }
    public double getSchutzwinkel()
    {
        double sum = 0;

        sum = 180 / Math.PI * Math.Atan((Math.Sqrt(2 * h * r - (h * h)) - r * Math.Sin(Math.Asin((Math.Sqrt(2 * h * r)) / (2 * r)))) / (h - r + r * (Math.Cos(Math.Asin(Math.Sqrt(2 * h * r) / (2 * r))))));

        return sum;
    }

```

Does someone see my mistake? I got the formula from an excel sheet.

EDIT: Okay, my problem was that I had a parsing error while creating the object or getting the user input, apparently solved it by accident. Ofc I have to add a simple exception, as Nick Dechiara said. Thank you very much for the fast reply, I appreciate it.

EDIT2: The exception in my excel sheet is:

```
if(h < 2) {h = 2}

```

so that's explaining everything and I wasn't paying attention at all. Thanks again for all answers.

```
int r = 45, h = 2;
sum = 77.14°

```