code:

Can't Copy and Paste this?

Click here for a copy-and-paste friendly version of this code!

 

Terms of Agreement:   

By using this code, you agree to the following terms...   

1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.   

2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   

3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 

4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.  

//     

//Author: Wilton Marranzini

//This program calculates the quadratic 

//     equation

#include 

#include 

void cal_root (float a, float b, float c, float & answer1, float & answer2);

void main()

    {

     float num_a;

    float num_b;

    float num_c;

    float answer1;

    float answer2;

    char repeat = 'y';

    while ((repeat == 'y')||(repeat == 'Y'))

        {

         cout<< "Enter the value for A\n";

        cin>> num_a;

        cout<< "Enter the value for B\n";

        cin>> num_b;

        cout<< "Enter the value for C\n";

        cin>> num_c;

         cal_root(num_a, num_b, num_c, answer1, answer2);

         cout<< "Would you like to do another quadratic equation. (Y- yes N- no)\n";

        cin>>repeat;

    }

}

void cal_root (float a, float b, float c, float & answer1, float & answer2)

    {

     float check;

    check = (pow(b,2))- 4 * a * c;

    if (check < 0 )

        {

        cout<< "The roots are complex and cannot be solved by this program yet!\n";

    }

    if (check == 0)

        {

         cout<< "The roots are both the same and are equal to -b/2a.\n";

        answer1 = -b/(2*a);

        answer2 = answer1;

        cout<< answer1 <

        cout<< answer2 <

    }

    if (a == 0)

        {

        cout<< "It is not a quadratic equation and use of this equation will"

          << " division by zero\n";

    }

    if (check > 0)

        {

        cout<< "Is positive there are two unequal, real roots.\n";

        answer1 = (-b + sqrt(pow(b,2)-4*a*c))/(2*a);

        answer2 = (-b - sqrt(pow(b,2)-4*a*c))/(2*a);

        cout<< answer1 <

        cout<< answer2 <

    }

    return;

}