0

Hey guys, I'm almost done with my homework assignment in an intro c++ class.

My assignment found here:

http://faculty.cs.niu.edu/~byrnes/csci240/pgms/240pgm2.htm

My problem is with the output of the roots. If you run my program with the same numbers as sample output #2 in the assignment, I only get one root to display.

I can't get the 2nd root to display, I also realize the 2nd root should be a different number than the first root, I'm not sure how to do this.

Here is my program:

```
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main()
{
double Acoe, Bcoe, Ccoe, Xvertex, Yvertex, Discriminant, Roots;
cout << "Enter an integer for A-coefficient (non-zero value):";
cin >> Acoe;
if (Acoe == 0)
{
cout << "ERROR: the A-coefficient MUST be non-zero. Try again:";
cin >> Acoe;
}
else
{
}
cout << "Enter an integer for B-coefficient:";
cin >> Bcoe;
cout << "Enter an integer for C-coefficient:";
cin >> Ccoe;
Xvertex = - Bcoe / ( 2 * Acoe);
Yvertex = ( Acoe * Xvertex * Xvertex ) + ( Bcoe * Xvertex ) + Ccoe;
Discriminant = Bcoe * Bcoe - 4 * Acoe * Ccoe;
Roots = ( -Bcoe + sqrt( Discriminant )) / ( 2 * Acoe );
cout << "Vertex Calculations" << endl;
cout << fixed << setprecision(3) << "A-coefficient: " << Acoe << endl;
cout << fixed << setprecision(3) << "B-coefficient: " << Bcoe << endl;
cout << fixed << setprecision(3) << "C-coefficient: " << Ccoe << endl;
cout << fixed << setprecision(3) << " The X Vertex: " << Xvertex << endl;
cout << fixed << setprecision(3) << " The Y Vertex: " << Yvertex << endl;
if (Acoe > 0)
{
cout << "The parabola opens UPWARD:" << endl;
}
else
{
cout << "The parabola opens DOWNWARD:" << endl;
}
if (Discriminant < 0)
{
cout << "There are no roots" << endl;
}
if (Discriminant == 0)
{
cout << "Root 1 X Coordinate: " << Roots << endl;
cout << "Root 2 X Coordinate: " << Roots << endl;
}
if (Discriminant > 0)
{
cout << "Root 1 X Coordinate: " << Roots << endl;
}
return 0;
}
```

Any random pointers/code simplification tips are welcome!

*Edited 3 Years Ago by mike_2000_17*: Fixed formatting