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;
cout<<"Please type in a."<<endl;
cin>>a;
cout<<"Please type in b."<<endl;
cin>>b;
cout<<"Please type in c."<<endl;
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;
}