Ask your own question, for FREE!
Computer Science 20 Online
OpenStudy (anonymous):

I cannot wrap my head around this C++ question: 1. Write a program that finds the solutions, if any, to a given quadratic equation. A quadratic equation is any equation written in the form ax^2 + bx+ c. Keep in mind division by 0 is not permitted and the discriminant b^2-4ac cannot be negative. Use the quadratic formula. Note: if you feel for some reason you do not want to give me the C++ code then you can give me in pseudo-code.

OpenStudy (anonymous):

This is literally exactly the code you need...just in java...not hard to figure out what it should be in c++ - change the system.outs to cout<<....etc...but this should help you out a lot! public static void main(String[] args) { System.out.print("This program solves a quadratic equation.\nEnter the coefficients a b c: "); //get the three variables from user Scanner reader= new Scanner (System.in); double a=reader.nextDouble(); double b=reader.nextDouble(); double c=reader.nextDouble(); //calculate discriminate to determine how many solutions and calculate them double disc=((b*b)-(4*a*c)); double quadP= (-b+Math.sqrt(disc))/(2*a)+0; double quadM= (-b-Math.sqrt(disc))/(2*a)+0; //equation with user's variables System.out.format("Equation: %.2f*x^2 + %.2f*x + %.2f = 0\n", a, b, c); if (a==0.0 && b==0 && c==0) { System.out.println("All real numbers are solutions."); } else if (a==0 && b==0) { System.out.println("There are no real solutions."); } else if (a==0) { double x= ((-c)/(b))+0; System.out.format("There is one real solution: %.2f.\n", x); } else { if (disc<0.00) { System.out.println("There are no real solutions."); } else { if (disc>0.00) { System.out.format("There are two real solutions: %.2f, %.2f.%n", quadM, quadP); } if (disc==0.00) { System.out.format("There is one real solution: %.2f.%n", quadP); } {

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!