Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

bunyonb

  • 3 years ago

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.

  • This Question is Closed
  1. fpmaker
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

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

  2. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy