Quadratic equation homework problem

Hello, im new to c++ programming. What i am suppose to do is create a program to solve quadratic equations. Now when i input numbers, it does not solve it correctly. Now i know there is something wrong, but i have no idea what it is. Please help.

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

using namespace std;

int main()
{
//Declaring variables
double a=double();
double b=double();
double c=double();
double exp=double();
double exp1=double();
double exp2=double();
double exp3=double();
double solut1=double();
double solut2=double();
double i=double();
int sqrt=int();
double disc=double();
double sol1=double();


//Changing background and text color, for my own personal reasons
system("COLOR 80");


cout<<"This program will provide solutions for an equation of the form\n"<<endl;
cout<<"\t\t\t\tA*x^2 + B*x + C = 0,\t\t\t\t"<<endl;
cout<<"where A, B, and C are integers, and A is not equal to zero."<<endl;
cout<<scientific;
cout<<"Enter value of A: ";
cin>>a;
cout<<endl;
cout<<"Enter value of B: ";
cin>>b;
cout<<endl;
cout<<"Enter value of C: ";
cin>>c;




system("cls");

cout<<scientific;

exp1=-b/(2*a);
disc=(b*b)-std::sqrt(4*a*c);
exp3=disc/(2*a);
exp=-b+-(b*b)-std::sqrt(4*a*c)/(2*a);
solut1=-b+(b*b)-std::sqrt(4*a*c)/(2*a);
solut2=-b-(b*b)-std::sqrt(4*a*c)/(2*a);
sol1=std::sqrt(4*a*c)/(2*a);


cout<<"This program will provide solutions for an equation of the form\n"<<endl;
cout<<"\t\t\t\tA*x^2 + B*x + C = 0,\t\t\t\t"<<endl;
cout<<"where A, B, and C are integers, and A is not equal to zero."<<endl;
cout<<"Enter value of A: "<<a<<"\n";
cout<<endl;
cout<<"Enter value of B: "<<b<<"\n";
cout<<endl;
cout<<"Enter value of C: "<<c<<"\n";
cout<<endl;



if(disc>0)
{
cout<<"The two real solutions are ";
cout<<"\tx= "<<setprecision(4)<<solut1<<endl;
cout<<"\t\t\tand";
cout<<"\tx= "<<setprecision(4)<<solut2<<endl;
}

else if(disc<0)
{
disc=disc*(-1);
cout<<"The two imaginary solutions are ";
cout<<"\tx= "<<setprecision(4)<<solut1*(-1)<<" + "<<" ( " << sol1 <<" ) "<<" *i "<<endl;
cout<<"\t\t\t\tand";
cout<<"\tx= "<<setprecision(4)<<
solut2*(-1)<<" - "<<" ( "<< sol1 <<" ) "<<" *i "<<endl;

}
else if(disc=0)
{
cout<<"No solutions will be calculated for a leading coefficient of 0!"<<endl;
}








return 0;
}
disc=(b*b)-4*a*c;
I've already done that but it doesn't change anything
So you're saying you changed your code from (b*b)-std::sqrt(4*a*c) to std::sqrt(b*b - 4*a*c)?
No I didn't, is that what I am doing wrong? Because I only want (4*a*c) to be in the square root.
Last edited on
Oh wow, I'm an idiot. Thanks.
Topic archived. No new replies allowed.