Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

bunyonb

  • one year 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
    • one year 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

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.