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);

```
A little late, but here is my solution:

```
using System;
using System.Collections.Generic;

namespace MyFunctions
{
    class Program
    {
        static void Main(string[] args)
        {
            printABCSolution(1, -3, 4);
            printABCSolution(1, -4, 4);
            printABCSolution(1, -5, 4);
            printABCSolution(9, 30, 25);
            printABCSolution(9, -15, 25);

            Console.ReadKey();
        }

        private static void printABCSolution(double a, double b, double c)
        {
            Console.WriteLine($"Solution a={a} b={b} c={c}");
            var solution = ABCMath.ABCFormula(a, b, c);
            Console.WriteLine($"# Solutions found: {solution.Count}");
            solution.ForEach(x => Console.WriteLine($"x={x}"));
        }

    }

    public static class ABCMath
    {
        public static List<double> ABCFormula(double a, double b, double c)
        {
            // Local formula
            double formula(int plusOrMinus, double d) => (-b + (plusOrMinus * Math.Sqrt(d))) / (2 * a);
            double discriminant = b * b - 4 * a * c;

            List<double> result = new List<double>();
            if (discriminant >= 0)
            {
                result.Add(formula(1, discriminant));
                if (discriminant > 0)
                    result.Add(formula(-1, discriminant));
            }
            return result;
        }
    }
}

```

Output:

```
Solution a=1 b=-3 c=4
# Solutions found: 0
Solution a=1 b=-4 c=4
# Solutions found: 1
x=2
Solution a=1 b=-5 c=4
# Solutions found: 2
x=4
x=1
Solution a=9 b=30 c=25
# Solutions found: 1
x=-1,66666666666667
Solution a=9 b=-15 c=25
# Solutions found: 0

```