LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-27-2012, 08:53 AM   #1
Razvanq
LQ Newbie
 
Registered: Jul 2012
Posts: 6

Rep: Reputation: Disabled
C++ syntax error before 'if'


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";
}
 
Old 07-27-2012, 09:33 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
you appear to be trying to invent an "while {...} else {...}" loop which doesn't exist
 
1 members found this post helpful.
Old 07-27-2012, 09:35 AM   #3
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
while-loops cannot have an else.

Code:
	if(j%2==0)
	{
		etapa=1;
		while(a!=0)
		{
			...
		}
		else
		{
			...
		}
	}
 
Old 07-27-2012, 01:01 PM   #4
Razvanq
LQ Newbie
 
Registered: Jul 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
i can't believe i havent noticed that. Thanks for the help

Last edited by Razvanq; 07-27-2012 at 01:15 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script.pl with sed shell calls: sh error syntax error near unexpected token `(' MMaddoxx Programming 7 11-24-2011 08:00 AM
Apache custom 500 error not showing after php syntax error vockleya Linux - Server 7 08-11-2011 04:42 PM
[python] syntax Error : invalid syntax Python_user Programming 2 09-06-2009 12:52 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM
ERROR running make when installing Nvidia drivers (syntax error) randyriver10 Linux - Software 5 02-21-2004 04:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration