Your name goes here add a description of this program her


// Your name goes here
//
// add a description of this program here.

#include <iostream>
#include <cmath>

using namespace std;

int main() {

double a, b, c; // coefficeints of equation
double disc; // the discriminant
double r1, r2, doubleroot;
double realroot, imaginaryroot

cout << \" this program will compute and print the roots of a quadratic equation \ \";
cout << \" ax^2 + bx + c = 0 \ \";
cout << \" the user will be prompted for the 3 coefficients \ \ \ \";


//computer input
cout << \" The value of a is: \";
cin >> a;
cout << \" The Value of b is: \";
cin >> b;
cout << \" The Value of c is: \";
cin >> c;


// computations

disc = b*b - 4 * a*c; // the discriminant


if (disc > 0) { // just a heads up, when i tried doing nested if else statement, it would not allow me to and it would just input the first if statment, the only way to get it was to do each individual else if statement, I\'ll add the pic of the pet I\'m talking about in my program
r1 = (-b + sqrt(disc)) / (2 * a); // root #1
r2 = (-b - sqrt(disc)) / (2 * a);
cout << \" the roots of the equation are: \ \";
cout << \" r1 is \" << r1 << endl;
cout << \" r2 is \" << r2 << endl;
}
else if (disc == 0) {
doubleroot = -b / (2 * a);
cout << \" The double root is: \" << doubleroot << endl;
}

// to do: add a nested if-else section here to handle the two cases:
// 1) one double root
// 2) two real roots
// you should be able to re-use the code below






else if (disc < 0) {
realroot = (-b / (2 * a);
imaginaryroot = sqrt(-disc) / (2 * a );
cout << \" there are no real roots for this equation \ \";
cout << \" r2 = \" << realroot << \"-\" << imaginaryroot << \"i\" << endl;
cout << \" r1 = \" << realroot << \"+ \" << imaginaryroot << \"i\" << endl;
}

return 0;
}
// Your name goes here
//
// add a description of this program here.

#include <iostream>
#include <cmath>

using namespace std;

int main() {

double a, b, c; // coefficeints of equation
double disc; // the discriminant
double r1, r2, doubleroot;
double realroot, imaginaryroot

cout << \" this program will compute and print the roots of a quadratic equation \ \";
cout << \" ax^2 + bx + c = 0 \ \";
cout << \" the user will be prompted for the 3 coefficients \ \ \ \";


//computer input
cout << \" The value of a is: \";
cin >> a;
cout << \" The Value of b is: \";
cin >> b;
cout << \" The Value of c is: \";
cin >> c;


// computations

disc = b*b - 4 * a*c; // the discriminant


if (disc > 0) { // just a heads up, when i tried doing nested if else statement, it would not allow me to and it would just input the first if statment, the only way to get it was to do each individual else if statement, I\'ll add the pic of the pet I\'m talking about in my program
r1 = (-b + sqrt(disc)) / (2 * a); // root #1
r2 = (-b - sqrt(disc)) / (2 * a);
cout << \" the roots of the equation are: \ \";
cout << \" r1 is \" << r1 << endl;
cout << \" r2 is \" << r2 << endl;
}
else if (disc == 0) {
doubleroot = -b / (2 * a);
cout << \" The double root is: \" << doubleroot << endl;
}

// to do: add a nested if-else section here to handle the two cases:
// 1) one double root
// 2) two real roots
// you should be able to re-use the code below






else if (disc < 0) {
realroot = (-b / (2 * a);
imaginaryroot = sqrt(-disc) / (2 * a );
cout << \" there are no real roots for this equation \ \";
cout << \" r2 = \" << realroot << \"-\" << imaginaryroot << \"i\" << endl;
cout << \" r1 = \" << realroot << \"+ \" << imaginaryroot << \"i\" << endl;
}

return 0;
}
to do: add a nested if-else section here to handle the two cases 1) one double root 2) two real roots ll you should be able to re-use the code below else if disc 0 )t -disc disc realroot b (2 a); imaginary root sqrt(disc) (2 a Cout r2 realroot imaginaryroot \"i\" endl. cout r1 realroot imaginary root \"i\" endi; return 0; put from: Build Output

Solution

working code:

#include <iostream>
#include <cmath>

using namespace std;

int main() {

double a, b, c; // coefficeints of equation
double disc; // the discriminant
double r1, r2, doubleroot;
double realroot, imaginaryroot;

cout << \" this program will compute and print the roots of a quadratic equation \ \";
cout << \" ax^2 + bx + c = 0 \ \";
cout << \" the user will be prompted for the 3 coefficients \ \ \ \";


//computer input
cout << \" The value of a is: \";
cin >> a;
cout << \" The Value of b is: \";
cin >> b;
cout << \" The Value of c is: \";
cin >> c;


// computations

disc = b*b - 4 * a*c; // the discriminant


if (disc > 0) { // just a heads up, when i tried doing nested if else statement, it would not allow me to and it would just input the first if statment, the only way to get it was to do each individual else if statement, I\'ll add the pic of the pet I\'m talking about in my program
r1 = (-b + sqrt(disc)) / (2 * a); // root #1
r2 = (-b - sqrt(disc)) / (2 * a);
cout << \" the roots of the equation are: \ \";
cout << \" r1 is \" << r1 << endl;
cout << \" r2 is \" << r2 << endl;
}
else if (disc == 0)
{
doubleroot = -b / (2 * a);
cout << \" The double root is: \" << doubleroot << endl;
}
else if (disc < 0)
{
realroot = (-b / (2 * a));
imaginaryroot = sqrt(-disc) / (2 * a );
cout << \" there are no real roots for this equation \ \";
cout << \" r2 = \" << realroot << \"-\" << imaginaryroot << \"i\" << endl;
cout << \" r1 = \" << realroot << \"+ \" << imaginaryroot << \"i\" << endl;
}

return 0;
}

Sample Output:

this program will compute and print the roots of a quadratic equation
ax^2 + bx + c = 0
the user will be prompted for the 3 coefficients


The value of a is: 1
The Value of b is: 1
The Value of c is: 1
there are no real roots for this equation
r2 = -0.5-0.866025i
r1 = -0.5+ 0.866025i

 // Your name goes here // // add a description of this program here. #include <iostream> #include <cmath> using namespace std; int main() { double
 // Your name goes here // // add a description of this program here. #include <iostream> #include <cmath> using namespace std; int main() { double
 // Your name goes here // // add a description of this program here. #include <iostream> #include <cmath> using namespace std; int main() { double
 // Your name goes here // // add a description of this program here. #include <iostream> #include <cmath> using namespace std; int main() { double

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site