# Thread: parse error before else

1. ## parse error before else

Hi. I am trying to program a short algebra routine to give me the answers to a quadratic function. The compiler says there are "parse errors before 'else'" on lines 35, 41 and 45. Somebody probably knows why. Thanx

code:

#include <iostream.h>
#include <stdlib.h>

int main()
{
//Solve a quadratic equation for x.
cout<<"Solve a*x^2 + b*x + c = 0, for x."<<endl;
cout<<""<<endl;
cout<<""<<endl;
//declare variables
double a,b,c,delta,x,x1r,x2r,real,imag;
cout<<""<<endl;
cin>>a;
cin>>b;
cin>>c;
cout<<""<<endl;
cout<<""<<endl;
cout<<"The value for a is "<<a<<". The value for b is "<<b<<". The value for c is "<<c<<"."<<endl;
cout<<""<<endl;
cout<<""<<endl;
system("PAUSE");
if(a==0)
if(b==0)
if(c==0)
cout<<"Indefinite equation."<<endl;
else
cout<<"Impossible equation."<<endl;
else
x=-c/b;
cout<<"One real solution x="<<x<<"."<<endl;
else
delta=b^2-4*a*c;
if(delta>0)
x1r=(-b+sqrt(delta))/(2*a);
x2r=(-b-sqrt(delta))/(2*a);
cout<<"Two real solutions x1="<<x1r<<"x2="<<x2r<<"."<<endl;
else
if(delta=0)
x=b/(2*a);
cout<<"One double solution x="<<x<<"."<<endl;
else
real=-b/(2*a)
imag=sqrt(-delta)/(2*a);
cout<<"Two complex solutions x1="<<real<<" + "<<imag<<"i and x2="<<real<<" - "<<imag<<"i."<<endl;
return 0;
}

2. Code:
```if(a==0)
if(b==0)
if(c==0)```
can't do this, do this:
Code:
`if(a == 0 && b == 0 && c == 0)`
and use Code Tags

3. ## Re: parse error before else

I think the illegal part is in bold here...

Originally posted by sdchem
Hi. I am trying to program a short algebra routine to give me the answers to a quadratic function. The compiler says there are "parse errors before 'else'" on lines 35, 41 and 45. Somebody probably knows why. Thanx

code:
Code:
```#include <iostream.h>
#include <stdlib.h>

int main()
{
//Solve a quadratic equation for x.
cout<<"Solve a*x^2 + b*x + c = 0, for x."<<endl;
cout<<""<<endl;
cout<<""<<endl;
//declare variables
double a,b,c,delta,x,x1r,x2r,real,imag;
cout<<""<<endl;
cin>>a;
cin>>b;
cin>>c;
cout<<""<<endl;
cout<<""<<endl;
cout<<"The value for a is "<<a<<".  The value for b is "<<b<<".  The value for c is "<<c<<"."<<endl;
cout<<""<<endl;
cout<<""<<endl;
system("PAUSE");
if(a==0)
if(b==0)
if(c==0)
cout<<"Indefinite equation."<<endl;
else
cout<<"Impossible equation."<<endl;
else
x=-c/b;
cout<<"One real solution x="<<x<<"."<<endl;
else
delta=b^2-4*a*c;
if(delta>0)
x1r=(-b+sqrt(delta))/(2*a);
x2r=(-b-sqrt(delta))/(2*a);
cout<<"Two real solutions x1="<<x1r<<"x2="<<x2r<<"."<<endl;
else
if(delta=0)
x=b/(2*a);
cout<<"One double solution x="<<x<<"."<<endl;
else
real=-b/(2*a)
imag=sqrt(-delta)/(2*a);
cout<<"Two complex solutions x1="<<real<<" + "<<imag<<"i and x2="<<real<<" - "<<imag<<"i."<<endl;
return 0;```
}
You put an else where there is no if.

4. the solution is to use curly brackets around the code that you want to group into an if statement