/*
 Solve the quadratic equation for 4 different solutions
 1. Give integers A,B, and C
 2. Solutions
 a. a is equal to zero (not defined)
 b. discriminant is < 0 (i.e. no real solutions)
 i. for any given imaginar solutions multiply times string i (where i = sqrt(-1))
 c. discriminant is > 0 (i.e. real solutions)
 d. discriminant is = 0 (i.e. only one solution)
 */

 

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>

using namespace std;

int main() {
    
    //Declaration & Initiations
    double a;
    double b;
    double c;
    double discriminant = 0;
    double x1;
    double x2;
    double i1;
    double z1;
    
    
    
    //Input
    
    
    
    int i;
    for (i = 1; i < 5 ; i++)
    {
    cout << "RUN# " << i << endl;
    cout << "This program will provide solutions for an equation of the form" << endl;
    cout << right << "                 A*x^2 + B*x + C = 0," << endl;
    cout << "where A, B, and C are integers, and A is not equal to zero.\n" << endl;
    
    cout << "Enter A, B, and C: ";
    cin >> a >> b >> c;
    
    //Process & Outputs
    discriminant = pow(b,2) - (4*a*c);
    
    
        
    
    if (a == 0) // no solutions
    {
        cout << "\nNo Solutions will be calculated for a leading coefficient of 0!" << endl;
        cout << "-----------------------------------------------------";
        cout << endl << endl << endl;
    }
    else if (discriminant > 0) // 2 real solutions
    {
        cout << fixed << showpoint << setprecision(4) << scientific;
        x1 = ((-b) + sqrt(discriminant)) / (2 * a);
        x2 = ((-b) - sqrt(discriminant)) / (2 * a);
        cout << "The two real solutions are x1 = " << x1 << endl;
        cout << "                       and x2 = " << x2 << endl;
        cout << "-----------------------------------------------------";
        cout << endl << endl << endl;
        
    }
    else if (discriminant < 0) // 2 imaginary solutions
    {
        cout << fixed << showpoint << setprecision(4) << scientific;
        
        x1 = - (b / (2 * a));
        z1 = abs(discriminant);
        i1 = sqrt(z1) / (2*a);
        cout << "The two imaginary solutions are x1 = " << x1 << " + " << i1 << "*i" << endl;
        cout << "                            and x2 = " << x1 << " - " << i1 << "*i" << endl;
        cout << "-----------------------------------------------------";
        cout << endl << endl << endl;
    }
    else if (discriminant == 0)    // 1 solution
    {
        cout << fixed << showpoint << setprecision(4) << scientific ;
        x1 = - (b / (2 * a));
        cout << "The one real solution is x = " << x1 << endl;
        cout << "-----------------------------------------------------";
        cout << endl << endl << endl;
    }
    
        
    }
    return 0;
}
gcc version 4.6.3