Really Simple Quadratic Formula

First real program I've made completely on my own, still working on the c++ language but would love to know what you guys think and possibly how you would've gone around making this. Thanks!

#include <iostream>
#include<math.h>

using namespace std;

void quadError(float a, float b,float c);
void quad(float a, float b, float c);

int main()
{
float a, b, c;
cout<<"ax^2+bx+c"<<endl;
cout<<"a = ";
cin>>a;
cout<<"b = ";
cin>>b;
cout<<"c = ";
cin>>c;
quad(a,b,c);
return 0;
}

void quadError(float a, float b,float c)
{
float discriminant = (b*b) - (4*a*c);
if(discriminant<0)
{
cout<<"discriminant was negative"<<endl;
}
if((2*a)==0)
{
cout<<"cannot divide by zero"<<endl;
}
}
void quad(float a, float b, float c)
{
float discriminant = (b*b) - (4*a*c);
if((discriminant>0) && (2*a))
{
float root1= (((-b) + sqrt((b*b) - (4*a*c)))/(2*a));
float root2= (((-b) - sqrt((b*b) - (4*a*c)))/(2*a));
cout<<"zeros are x = "<< root1 <<" and x = " << root2 <<endl;
}
else
{
quadError(a,b,c);
}
}
Use <cmath> instead, the .h ones are deprecated.
Last edited on
Topic archived. No new replies allowed.