Question: Write a C++ program that asks a user to enter the coefficients a, b, and c of a quadratic equation ax^2 + bx + c

Write a C++ program that asks a user to enter the coefficients a, b, and c of a quadratic equation ax^2 + bx + c = 0 and outputs the solution(s). The program should indicate if there are no real solutions.

Tips and Hints:

  • The coefficients should be doubles (not necessarily integers).
  • The pow function is in the math.h library so you'll need #include in the header of the program.
  • Remember from math class, that the discriminant = sqrt(b * b - 4 * a * c) tells us about the solutions:
    • if discriminant > 0, we have two real solutions,
    • if discriminant = 0, we have one real solution,
    • if discriminant < 0, we have no real solutions.

Example 01:

Enter a: 1

Enter b: -1

Enter c: -6

You have two real solutions: -2, 3

Example 02:

Enter a: 1

Enter b: 0

Enter c: 1

You have no real solutions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!