i have an unusual syntax error reported by the compiler, and i cant find what is wrong.
I compile with the MINGW Developer Studio.
Help me please. This is driving me crazy!!!!!
One error i get looks like this.
Code:
ex4Lectie3S3.cpp:48: error: syntax error before `else'
And this is the line
Code:
}
}
}
else
{
etapa=2;
while(a!=0)
{
And this is the other error:
Code:
ex4Lectie3S3.cpp: At global scope:
ex4Lectie3S3.cpp:80: error: syntax error before `if'
At this line
Code:
palindrom=0;
}
}
}
if(etapa==1)
if(palindrom==1)
return nr;
else
This is the whole program:
Code:
#include<iostream.h>
int cif(int a,int b) //numarul aparitiilor in b ale lui a
{
int cif,j=0;
while(a!=0)
{
cif=a%10;
a=a/10;
if(cif==b)
j++;
}
return j;
}
int exb(int a)
{
int j=0,aux,ct=1,palindrom=1,gata,etapa=0,nr=0,cif=0,cif2=0,posibil=0;
nr=a;
aux=a;
while(aux!=0)
{
aux=aux/10;
j++;
}
aux=a;
if(j%2==0)
{
etapa=1;
while(a!=0)
{
cif=a%10;
a=a/10;
aux=a;
while(gata==0)
{
while(aux!=0)
{
cif2=aux%10;
if(cif==cif2)
ct++;
}
if(ct!=2)
{
gata=1;
palindrom=0;
}
}
}
else
{
etapa=2;
while(a!=0)
{
cif=a%10;
a=a/10;
aux=a;
while(gata==0)
{
while(aux!=0)
{
cif2=aux%10;
if(cif==cif2)
ct++;
}
if(ct!=2)
if(ct==1)
posibil++;
else
{
palindrom=0;
gata=1;
}
}
if(posibil==1)
palindrom=1;
else
palindrom=0;
}
}
}
if(etapa==1)
if(palindrom==1)
return nr;
else
return 0;
else
if(palindrom==1)
return nr;
else
return 0;
}
int main()
{
int a,b,n;
cout<<"Introduceti numarul a ";
cin>>a;
cout<<endl<<"Introduceti numarul b ";
cin>>b;
cout<<"Numarul "<<b<<" se afla de "<<cif(a,b)<<" ori in numarul "<<a;
cout<<endl<<"Introduceti numarul n de exact 8 cifre ";
cin>>n;
while(n<10000000 || n>99999999)
cin>>n;
if(exb(n)==0)
cout<<"Numarul introdus nu este paldindrom.";
else
cout<<"Numarul introdus este palindrom";
}