You are on page 1of 2

#include <iostream>

#include <string>
#include <cmath>
using namespace std;

int Get_Coefficients(*a,*b,*c);
int Calc_Discriminant();
int Calc_root();

int main()
{
bool loop= true;
string answer;
Get_Coefficients(&a,&b,&c);
Calc_Discriminant();
Calc_root();
cout<<"do you want to do this again? ";
cin >>answer;
while( true )
{
Get_Coefficients(&a,&b,&c);
int Calc_Discriminant();
int Calc_root();
}

return 0;
}

int Get_Coefficients(int *a,int *b,int *c)


{
cout<<"Enter the first coefficient : ";
cin >>*a;
cout<<"Enter the second coefficient : ";
cin>> *b;
cout<< "Enter the third coefficient : ";
cin >> *c;
return 0;
}

int Calc_Discriminant()
{
root_1= -b + (sqrt(b*b - 4ac))/2a;
root_2 = -b - (sqrt(b*b - 4ac))/2a;
discriminant = b*b - 4*a*c ;

if (discriminant > 0 )
{
return real;
}
else if(discriminant == 0 )
{
return same;
}
else
{
return imaginary;
}
}
int Calc_root()
{
if(discriminant > 0)
{
x1 = root_1 ;
x2 = root_2;
cout<<"The roots are real and different \n" << "Root 1 is : " << x1 << endl
<< "Root 2 is : "<< x2 <<endl;
}
else if (discriminant == 0)
{
x1 = root_1;
x2 = root_1;
cout<< "The roots are the same \n" << "Root 1 is : " << x1 << endl
<< "Root 2 is : "<< x2 <<endl;
}
else
{
x1 = (float) -b/(2*a);
x2 = sqrt(-discriminant)/ 2*a ;
cout << "The root are real and imaginary \n" << "Root 1 is : " << x1 <<
endl
<< "Root 2 is : "<< x2 <<endl;
}
return 0;
}

You might also like