Question
#include #include using namespace std; int main() { double a, b, c, x1, x2, discriminant, real, imaginary; cout < < Enter coefficients a, b and
#include
int main() {
double a, b, c, x1, x2, discriminant, real, imaginary;
cout << "Enter coefficients a, b and c: "; cin >> a >> b >> c; discriminant = b * b - 4 * a * c; if (a == 0) { cout << "The equation is not quadratic" << endl; return 0; }
if (discriminant > 0) { x1 = (-b + sqrt(discriminant)) / (2 * a); x2 = (-b - sqrt(discriminant)) / (2 * a); cout << "Roots are real." << endl; cout << "x1 = " << x1 << endl; cout << "x2 = " << x2 << endl; }
else if (discriminant < 0) { real = -b / (2 * a); imaginary = sqrt(-discriminant) / (2 * a); cout << "Roots are complex." << endl; cout << "x1 = " << real << "+" << imaginary << "i" << endl; cout << "x2 = " << real << "-" << imaginary << "i" << endl; } return 0; }
After printing the roots, query the user if he/she wishes to compute the roots again for another set of coefficients.
I don't know how to query the user to if he /she wishes to compute roots again so please help. just add a few line code to the above code for the user to query if he/she want to compute roots again. thanks.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started