expected primary-expression before "else"

Hey guy it from about 2 hrs that iam trying to fix this errors but no luck o far.So i have this assigment for an introductory C++ Class and iam getting
2 errors 22 1- expected `;' before '(' token and 2-31 expected primary-expression before "else". Any clues why so?Iam currently using DEV C++ 4.9.9.2



//Solve a linear algebra system using Kramers rule!*****
//******************************************************
#include <stdlib.h>
#include <iostream.h>


int main()
{
float a,b,c,d,e,f,x,y;
cout <<"The equations are in the folowing form\n";
cout <<"| ax+by=e\n"; //Show the equations form ,indicating the coefficents
cout <<"| cx+dy=f\n"; //Show the equations form ,indicating the coefficents
cout <<"***Input the koefficents***\n";
cout <<"a=";cin>>a; // *****************************
cout <<"b=";cin>>b; // * *
cout <<"c=";cin>>c; // * Declare the Coeficents *
cout <<"d=";cin>>d; // * *
cout <<"e=";cin>>e; // * *
cout <<"f=";cin>>f; // *****************************
if

((a*d)-(b*c)) && ((a*d)-(b*c)) !=0 //Check if there is division by 0


x=((e*d)-(b*f))/((a*d)-(b*c));
y=((a*f)-(e*c))/((a*d)-(b*c));

cout <<"x="<<x<<";"; //Show the results
cout <<"y="<<y<<"\n"; //Show the results

else

cout<<"There is no solution for this system"; //in case of division by 0 , there is no solution to the sytem


system ("pause");
return (0);


}
else should be paired with an if statement.
Your if statement should be on the same line as the code it is checking, and you need the ( ) to cover the != 0 as well. For example
if ( ((a*d)-(b*c)) && ((a*d)-(b*c)) != 0 )

Also make sure you are using braces so all of the code after the if statement is included within it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

        float a,b,c,d,e,f,x,y;

	cout <<"The equations are in the folowing form\n";
	cout <<"| ax+by=e\n"; //Show the equations form ,indicating the coefficents
	cout <<"| cx+dy=f\n"; //Show the equations form ,indicating the coefficents
	cout <<"***Input the koefficents***\n";
	cout <<"a=";cin>>a; // *****************************
	cout <<"b=";cin>>b; // * *
	cout <<"c=";cin>>c; // * Declare the Coeficents * 
	cout <<"d=";cin>>d; // * *
	cout <<"e=";cin>>e; // * *
	cout <<"f=";cin>>f; // *****************************

	if ( ((a*d)-(b*c)) && ((a*d)-(b*c)) != 0 )
	{

		x=((e*d)-(b*f))/((a*d)-(b*c));
		y=((a*f)-(e*c))/((a*d)-(b*c));

		cout <<"x="<<x<<";"; //Show the results
		cout <<"y="<<y<<"\n"; //Show the results
	}

	else 
	{
		cout<<"There is no solution for this system"; //in case of division by 0 , there is no solution to the sytem
	}
Topic archived. No new replies allowed.