I'm making a console app that solves quadratics. so far, it can correctly identify the number of roots, but when it actually tries to calculate them, i get the wrong numbers. WHAT AM I DOING WRONG? this is supposed to be SIMPLE. Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { public static double QuadraticEquationPositive(double a, double b, double c) { double Solution1 = (-b + Math.Sqrt((b * b) - (4 * a * c))) / 2 * a; return Solution1; } public static double QuadraticEquationNegative(double a, double b, double c) { double Solution2 = (-b - Math.Sqrt((b * b) - (4 * a * c))) / 2 * a; return Solution2; } static void Main(string[] args) { Console.WriteLine("Ax^2 + Bx + C"); Console.WriteLine(); Console.WriteLine("Please enter value of quadratic coefficient (Must be non-zero): "); string A = Console.ReadLine(); double AValue = Convert.ToDouble(A); Console.WriteLine("Please enter value of linear coefficient: "); string B = Console.ReadLine(); double BValue = Convert.ToDouble(B); Console.WriteLine("Please enter value of constant: "); string C = Console.ReadLine(); double CValue = Convert.ToDouble(C); double D = (BValue * BValue) - (4 * AValue * CValue); if (D < 0) { Console.WriteLine("There are no solutions for this equation."); } if (D == 0) { Console.WriteLine("This equation has one solution: " + QuadraticEquationPositive(AValue, BValue, CValue)); } if (D > 0) { Console.WriteLine("This equation has 2 solutions: " + QuadraticEquationPositive(AValue, BValue, CValue) + " and " + QuadraticEquationNegative(AValue, BValue, CValue)); } Console.ReadLine(); } } }

2x^2 + 8x + 2 that should give you -0.2679491924311228 and -3.732050807568877 but my program gives like, -.something and -14.something.

your order of operations is off. I just followed it, and I see where you got it wrong. Code: public static double QuadraticEquationPositive(double a, double b, double c) { double Solution1 = (-b + Math.Sqrt((b * b) - (4 * a * c))) [B]/ 2 * a;[/B] return Solution1; } public static double QuadraticEquationNegative(double a, double b, double c) { double Solution2 = (-b - Math.Sqrt((b * b) - (4 * a * c))) [B]/ 2 * a;[/B] return Solution2; } look at the bold, what it's going to do is divide the whole thing by 2, and then multiply THAT by a. corrected functions: Code: public static double QuadraticEquationPositive(double a, double b, double c) { double Solution1 = (-b + Math.Sqrt((b * b) - (4 * a * c))) /( 2 * a); return Solution1; } public static double QuadraticEquationNegative(double a, double b, double c) { double Solution2 = (-b - Math.Sqrt((b * b) - (4 * a * c))) /( 2 * a); return Solution2; }

ALL RIGHT! THANKS! I never would have caught that tiny mistake on my own. It works good now. and Jac0b, as soon as i'm finished, you can get the first copy. why do you want it anyway?

It looks like it would make factoring quadratics quite easy. I'm in math 252 atm. just thought it'd be neat

ok. now, is it ok as a console app, or would you like a windows form? windows form would probly be more comfortable. you could clear and start over without exiting, and stuff like that.

windows app for sure. Idk if this is possible for you but what about it working on a mac? i run both OS's so jw

i wouldn't know anything about getting it to run on a mac. I only use macs for design. I'm strictly Windows when it comes to programming. but windows form it is then. i'll have it ready in a few days, because i'm probably going to be super-busy this week.

erm, you CAN keep it in fractions if you want. Just check to see if sqrt gives decimals, and if so, just output something such as "sqrt 10" etc...