Question: I'm having problem with this question: C++ question!! The solution of the equation ax2 + bx + c has 6 cases, that can occur with

I'm having problem with this question: C++ question!!

The solution of the equation ax2 + bx + c has 6 cases, that can occur with various values of a, b, and c. Test for these 6 cases in the order given here. Do not compute any values until you have determined what calculations are needed. The 6 cases are: When a, b, and c are all zero, any value of x is a solution. Print: Any value of x is a solution. When a and b are zero and c is not, no solution exists. Print: No solution exists. When a is zero and b is not zero, the only solution is x = -c/b. Calculate the value of x and print the solution. The remaining three cases are determined by the value of the determinant. The determinant is b2 - 4ac. Compute and save the value of the dererminant now. You can use the value of the determinant you saved to select one of the remaining three cases. When the determinant is zero, the only solution is x = -b/2a. Calculate the value of x and print the solution. When the determinant is positive, two solutions are given by the following two expressions: x1 = ( -b + b2 - 4ac ) / 2a x2 = ( -b - b2 - 4ac ) / 2a Print both solutions. When the determinant is negative, the solutions have an imaginary component. Print: The solutions have an imaginary component. If you are fimiliar with imaginary numbers, you may compute and print the result, but this is not required.

Test it 7 times: a = 0 b = 0 c = 0

a = 0 b = 0 c = 4

a = 0 b = 8 c = -12

a = 2 b = 4 c = 2

a = 2 b = 2 c = 0

a = 100 b=100 c= -11

a = 1 b = 1 c = 1

Check your results by hand, by substituting your results back into the equation and verify that they are roots. this is the code I've come up with, but I can't seem to get have it work for the fifth case: a=2 b=2 and c=0. Can you please help guide me in the proper direction and see what is wrong with my code.

CODE I'VE CREATED:

#include #include #include

using namespace std;

int main() { double a,b,c; double determinant = pow(b,2) - (4 * a *c); double x3 = -c / b; double x4; double x1; double x2;

cout << "Enter value for a: "; cin >> a; cout << "Enter a value for b: "; cin >> b; cout << "Enter a value for c: "; cin >> c;

if (a == 0 && b == 0) { if (c == 0) cout << "Any value of x is a solution" << endl; } if (a == 0 && b == 0 && c != 0) { cout << "No solution exists" << endl; } if (a == 0 && b != 0) { x3 = -c/b; cout << x3 << endl; }

if (determinant == 0 && a != 0) { determinant = pow(b,2) - (4 * a *c); x4 = -b / (2 * a); cout << x4 << endl;

}

if (determinant > 0) { x1 = (-b + sqrt(pow(b,2)- (4*a*c))) / (2 * a); x2 = (-b - sqrt(pow(b,2)- (4*a*c))) / (2 * a); cout << x1<< endl; cout << x2 << endl; }else { if (determinant<0) { cout << "The solutions have an imaginary component." << endl; }

}

return 0; }

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!