All pastes #1511733 Raw Edit

[phear]crippler

public cpp v1 · immutable
#1511733 ·published 2009-07-30 01:42 UTC
rendered paste body
/*AUTHOR:  David Chapman ([phear]crippler)FILE:    complexQuadRootZeros.cxxWEBSITE: www.phear-gaming.netPURPOSE: This program will compute all the roots/zeros of a quadratic equation (including imaginary ones).*/#include <iostream>#include <cmath>using namespace std;int main(void){    float a, b, c, y1, y2, radicand;    char  again;    cout << "This program will compute the roots/zeros of a quadratic equation (including imaginary ones).\n\n";    do    {        cout << "Please enter a, b, and c from the form: y = f(x) = ax^2 + bx + c\n"             << "a = ";        cin  >> a;        cout << "b = ";        cin  >> b;        cout << "c = ";        cin  >> c;        radicand = ((b*b)-(4*a*c));        if ( ((b * b)-(4 * a * c)) < 0 )        {            radicand = -1 * radicand;            y1 = ((-1 * b) + ( sqrt(radicand) ))/(2 * a);            y2 = ((-1 * b) - ( sqrt(radicand) ))/(2 * a);            if ( y1 == y2 )            {                cout << "\a\nThe root is: " << y1 << "i\n\n\n";            }            else            {                cout << "\a\nThe roots are: " << y1 << "i and " << y2 << "i\n\n\n";            }        }        else        {            y1 = ((-1 * b) + (sqrt(radicand)))/(2 * a);            y2 = ((-1 * b) - (sqrt(radicand)))/(2 * a);            if (y1 == y2)            {                cout << "\a\nThe root is: " << y1 << "\n\n\n";            }            else            {                cout << "\a\nThe roots are: " << y1 << " and " << y2 << "\n\n\n";            }        }        cout << "Do another? (y or n): ";        cin  >> again;    }    while (again == 'Y' || again == 'y');}