I am trying to create a simple quadratic equation (x^2 + px + q = 0) solver but the answer I get is always wrong. My code looks like this
double p, q;
Console.Write("Insert the value of p: ");
int p = int.Parse(Console.ReadLine());
Console.Write("Insert the value of q: ");
int q = int.Parse(Console.ReadLine());
Console.WriteLine("x1 = " + (-p/2 + Math.Sqrt((p/2) ^ 2 - q )));
Console.WriteLine("x2 = " + (-p/2 - Math.Sqrt((p/2) ^ 2 - q)));
My guess is that there is something wrong with the "x1 = " + (-p/2 + Math.Sqrt((p/2) ^ 2 - q )));
and the x2 = + (-p/2 - Math.Sqrt((p/2) ^ 2 - q)));
parts.
Any help would be greatly appreciated.