Question: I am trying to make a program that calculates the answer of a quadratic equation with the general formula but i am encountering a few errors.
The way I have my Windows Form Application set up it asks for a, b, and c, and substitutes them in the general formula.
I have 3 text boxes, one for each value of a, b and c and one more for the answer, and it is supposed to work with a button I called "calculate". 
My problem is that when I try something other than a perfect trinomial square, the answer comes up as NaN.
Here is some of the code I have:

```
private void textBox1_TextChanged(object sender, EventArgs e)
    {
        a = Double.Parse(textBox1.Text);
    }

```

^ This is how I am assigning values to the variables

```
double sqrtpart = b * b - 4 * a * c;
        answer = (b + Math.Sqrt(sqrtpart)) / 2 * a;
        textBox4.Text = answer.ToString();

```

Answer: 
group 2a and make sure values are valid (b^2 > 4ac)

```
answer = (b + Math.Sqrt(sqrtpart)) / (2 * a);

```
If you want your calculator to be able to compute complex numbers try the following

```
 string ans = "";
        double root1 = 0;
        double root2 = 0;
        double b = 0;
        double a = 0;
        double c = 0;
        double identifier = 0;

        a =Convert.ToDouble(Console.ReadLine());
        b = Convert.ToDouble(Console.ReadLine());
        c = Convert.ToDouble(Console.ReadLine());

        identifier = b * b - (4 * a * c);

        if (identifier > 0)
        {
            root1 = (-b+(Math.Sqrt(identifier)/(2*a)));
            root2 = (-b - (Math.Sqrt(identifier) / (2 * a)));
            string r1 = Convert.ToString(root1);
            string r2 = Convert.ToString(root2);
            ans = "Root1 =" + r1 + "Root2 = " + r2;
            Console.WriteLine(ans);
        }

        if (identifier < 0)
        {
            double Real = (-b / (2 * a));
            double Complex = ((Math.Sqrt((identifier*(-1.00))) / (2 * a)));
            string SReal = Convert.ToString(Real);
            string SComplex = Convert.ToString(Complex);
            ans = "Roots = " + SReal + "+/-" + SComplex + "i";
            Console.WriteLine(ans);
        }

        if (identifier == 0)
        {
            root1 = (-b / (2 * a));
            string Root = Convert.ToString(root1);
            ans = "Repeated roots : " + Root;
        }

```