Expression syntax error in function main

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hexer
    New Member
    • Feb 2007
    • 4

    Expression syntax error in function main

    Hi and good day to all...I am new to the C language and whenever I tried to run the program I made, it won't because it says it has an "expression syntax error in function main"..what I don't get is that I know I had it done correctly and just to make sure if I was mistaken or not in writing my programs, I even copied some exapmles of programs in my book and and even in the internet...when I tried running these programs, they do not run too and says exactly the same error I've committed..plea se help!..
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    A syntax error means that that code that you have written or copied into your environment was wrong or is missing some important part. If you copy and paste your code to this forum we can help you search for syntax errors. Syntax errors are the easiest errors to correct so it should be no trouble. Be sure to use "CODE" tags around your code when you copy and paste it.

    Comment

    • bakimariano12
      New Member
      • Apr 2009
      • 1

      #3
      can u help me because of expression syntax in function main!

      Code:
      #include<stdio.h>
      #include<string.h>
      #define p printf
      #define s scanf
      #define g gotoxy
      
      main()
      {
      	int ctr,count;
      	char log[10],pass[10];
      	char ans, wrd[30], letter='a';
      	float Q1,Q2,Q3,gen_ave,mid,aten,agg,fQ1,fQ2,fQ3,fgen_ave,fa,fmid,faten,fagg,b,a,f;
      	int c,choice;
      	int gc,a1,a2,equal;
      
      
      	Q1=0;
      	Q2=0;
      	Q3=0;
      	mid=0;
      	aten=0;
      	fQ1=0;
      	fQ2=0;
      	fQ3=0;
      	fmid=0;
      	faten=0;
      
      	clrscr();
      	p("Username: ");
      	g(1,2);
      	p("Enter your password: ");
      
      	g(11,1);
      	s("%s",log);
      	c=strcmp(log,"mariano");
      
      	g(22,2);
      	s("%s",pass);
      	c=strcmp(pass,"lenonmariano");
      
      
      	if(c==0)
      	{
      		clrscr();
      		g(30,2);
      		p("Main Menu");
      		g(30,5);
      		p("1. Computation");
      		g(30,6);
      		p("2. Grade Computation");
      		g(30,7);
      		p("3. String Manipulation");
      		g(30,8);
      		p("4. Vowel");
      		g(30,9);
      		p("5. Exit");
      		g(30,11);
      		p("Choose [1-5]: ");
      		s("%d",&choice);
      	}
      	else
      		p("Wrong Username or Password");
      
      	if(choice==1)
      	{
      		clrscr();
      		g(35,2); p("Main Menu");
      		g(33,5); p("1. ADDITION");
      		g(33,6); p("2. SUBTRACT");
      		g(33,7); p("3. MULTIPLY");
      		g(33,8); p("4. DIVIDE");
      		g(33,9); p("5. QUIT");
      		g(28,11); p("Choose Computation [1-5]: ");
      		s("%d",&gc);
      	}
      	else if(choice==2)
      	{
      		clrscr();
      		g(5,3); p("Q1");
      		g(10,3); p("Q2");
      		g(15,3); p("Q3");
      		g(20,3); p("Midterm");
      		g(30,3); p("Attendance");
      		g(45,3); p("Over All Grade");
      
      		g(5,4); s("%f",&Q1);
      		g(10,4); s("%f",&Q2);
      		g(15,4); s("%f",&Q3);
      
      		gen_ave=(Q1+Q2+Q3)/3;
      
      		g(20,4); s("%f",&mid);
      		g(30,4); s("%f",&aten);
      		g(45,4); agg=(gen_ave*.3)+(mid*.6)+(aten*.1);
      		p("%.2f",agg);
      		getch();
      
      		clrscr();
      
      		g(5,3); p("Q1");
      		g(10,3); p("Q2");
      		g(15,3); p("Q3");
      
      		g(5,3); p("Q1");
      		g(10,3); p("Q2");
      		g(15,3); p("Q3");
      		g(20,3); p("Final Term");
      		g(30,3); p("Attendance");
      		g(45,3); p("Over All Grade");
      
      		g(5,4); s("%f",&fQ1);
      		g(10,4); s("%f",&fQ2);
      		g(15,4); s("%f",&fQ3);
      
      		fgen_ave=(fQ1+fQ2+fQ3)/3;
      
      		g(20,4); s("%f",&fmid);
      		g(30,4); s("%f",&faten);
      
      		g(45,4); fagg=(fmid*.6)+(faten*.1)+(fgen_ave*.3);
      		p("%.2f",fagg);
      
      		getch();
      		clrscr();
      
      		g(5,3); p("Final Grade");
      		b=agg*.40;
      		a=fagg*.60;
      
      		g(5,4);
      		f=b+a;
      		p("%.2f",f);
      	}
      	else if(choice==3)
      	{
      		clrscr();
      		count=0;
      			g(22,8); p("Enter A String: ");
      			s("%s",&wrd);
      			g(22,9);
      				for(ctr=0; (ctr(=strlen(wrd)-1); ctr++)
      				{
      					if(wrd[ctr]==letter)
      					{
      						count=count+1;
      					}
      				}
      		p("Your letter is: ");
      		p("%i",count);
      
      	}
      	getch();
      }
      email me if you see my error! <Removed>! help me!
      Last edited by JosAH; Apr 2 '09, 11:16 AM.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        1.) You did not use the code tags suggested above.
        2.) main must return an int. Read Ten Common Silly Mistakes
        3.) Where did you declare clrscr which you are calling often? Perhaps you forgot to include conio.h (which is not available on all platforms and so should be avoided)

        Comment

        • newb16
          Contributor
          • Jul 2008
          • 687

          #5
          email me if you see my error
          You confused angle bracket and parenthesis in the line pointed by compiler. Btw, you could have posted its number here so that I didn't copypaste your code and compile it for you.

          Comment

          • duraisakthy
            New Member
            • Aug 2012
            • 1

            #6
            //Just try to execute now you will get answer...


            #include<stdio. h>
            #include<string .h>
            #define p printf
            #define s scanf
            #define g gotoxy

            void main()
            {
            int ctr,count;
            char log[10],pass[10];
            char ans, wrd[30], letter='a';
            float Q1,Q2,Q3,gen_av e,mid,aten,agg, fQ1,fQ2,fQ3,fge n_ave,fa,fmid,f aten,fagg,b,a,f ;
            int c,choice;
            int gc,a1,a2,equal;


            Q1=0;
            Q2=0;
            Q3=0;
            mid=0;
            aten=0;
            fQ1=0;
            fQ2=0;
            fQ3=0;
            fmid=0;
            faten=0;

            clrscr();
            p("Username: ");
            g(1,2);
            p("Enter your password: ");

            g(11,1);
            s("%s",log);
            c=strcmp(log,"m ariano");

            g(22,2);
            s("%s",pass);
            c=strcmp(pass," lenonmariano");


            if(c==0)
            {
            clrscr();
            g(30,2);
            p("Main Menu");
            g(30,5);
            p("1. Computation");
            g(30,6);
            p("2. Grade Computation");
            g(30,7);
            p("3. String Manipulation");
            g(30,8);
            p("4. Vowel");
            g(30,9);
            p("5. Exit");
            g(30,11);
            p("Choose [1-5]: ");
            s("%d",&choice) ;
            }
            else
            p("Wrong Username or Password");

            if(choice==1)
            {
            clrscr();
            g(35,2); p("Main Menu");
            g(33,5); p("1. ADDITION");
            g(33,6); p("2. SUBTRACT");
            g(33,7); p("3. MULTIPLY");
            g(33,8); p("4. DIVIDE");
            g(33,9); p("5. QUIT");
            g(28,11); p("Choose Computation [1-5]: ");
            s("%d",&gc);
            }
            else if(choice==2)
            {
            clrscr();
            g(5,3); p("Q1");
            g(10,3); p("Q2");
            g(15,3); p("Q3");
            g(20,3); p("Midterm");
            g(30,3); p("Attendance") ;
            g(45,3); p("Over All Grade");

            g(5,4); s("%f",&Q1);
            g(10,4); s("%f",&Q2);
            g(15,4); s("%f",&Q3);

            gen_ave=(Q1+Q2+ Q3)/3;

            g(20,4); s("%f",&mid);
            g(30,4); s("%f",&aten) ;
            g(45,4); agg=(gen_ave*.3 )+(mid*.6)+(ate n*.1);
            p("%.2f",agg) ;
            getch();

            clrscr();

            g(5,3); p("Q1");
            g(10,3); p("Q2");
            g(15,3); p("Q3");

            g(5,3); p("Q1");
            g(10,3); p("Q2");
            g(15,3); p("Q3");
            g(20,3); p("Final Term");
            g(30,3); p("Attendance") ;
            g(45,3); p("Over All Grade");

            g(5,4); s("%f",&fQ1);
            g(10,4); s("%f",&fQ2);
            g(15,4); s("%f",&fQ3);

            fgen_ave=(fQ1+f Q2+fQ3)/3;

            g(20,4); s("%f",&fmid) ;
            g(30,4); s("%f",&faten );

            g(45,4); fagg=(fmid*.6)+ (faten*.1)+(fge n_ave*.3);
            p("%.2f",fagg );

            getch();
            clrscr();

            g(5,3); p("Final Grade");
            b=agg*.40;
            a=fagg*.60;

            g(5,4);
            f=b+a;
            p("%.2f",f);
            }
            else if(choice==3)
            {
            clrscr();
            count=0;
            g(22,8); p("Enter A String: ");
            s("%s",&wrd);
            g(22,9);
            for(ctr=0;(ctr< =strlen(wrd)-1); ctr++)
            {
            if(wrd[ctr]==letter)
            {
            count=count+1;
            }
            }
            p("Your letter is: ");
            p("%i",count) ;

            }
            getch();
            }

            Comment

            • Piya123
              New Member
              • Feb 2013
              • 1

              #7
              Thank u so much... your answer helped me a lot.. thanx once again...

              Comment

              • pritika
                New Member
                • Apr 2016
                • 1

                #8
                #include<conio. h>
                #include<stdio. h>
                #include<string .h>
                #define p printf
                #define s scanf
                #define g gotoxy

                void main()
                {
                int ctr,count;
                char log[10],pass[10];
                char ans, wrd[30], letter='a';
                float Q1,Q2,Q3,gen_av e,mid,aten,agg, fQ1,fQ2,fQ3,fge n_ave,fa,fmid,f aten,fagg,b,a,f ;
                int c,choice;
                int gc,a1,a2,equal;


                Q1=0;
                Q2=0;
                Q3=0;
                mid=0;
                aten=0;
                fQ1=0;
                fQ2=0;
                fQ3=0;
                fmid=0;
                faten=0;

                clrscr();
                p("Username: ");
                g(1,2);
                p("Enter your password: ");

                g(11,1);
                s("%s",log);
                c=strcmp(log,"m ariano");

                g(22,2);
                s("%s",pass);
                c=strcmp(pass," lenonmariano");


                if(c==0)
                {
                clrscr();
                g(30,2);
                p("Main Menu");
                g(30,5);
                p("1. Computation");
                g(30,6);
                p("2. Grade Computation");
                g(30,7);
                p("3. String Manipulation");
                g(30,8);
                p("4. Vowel");
                g(30,9);
                p("5. Exit");
                g(30,11);
                p("Choose [1-5]: ");
                s("%d",&choice) ;
                }
                else
                p("Wrong Username or Password");

                if(choice==1)
                {
                clrscr();
                g(35,2); p("Main Menu");
                g(33,5); p("1. ADDITION");
                g(33,6); p("2. SUBTRACT");
                g(33,7); p("3. MULTIPLY");
                g(33,8); p("4. DIVIDE");
                g(33,9); p("5. QUIT");
                g(28,11); p("Choose Computation [1-5]: ");
                s("%d",&gc);
                }
                else if(choice==2)
                {
                clrscr();
                g(5,3); p("Q1");
                g(10,3); p("Q2");
                g(15,3); p("Q3");
                g(20,3); p("Midterm");
                g(30,3); p("Attendance") ;
                g(45,3); p("Over All Grade");

                g(5,4); s("%f",&Q1);
                g(10,4); s("%f",&Q2);
                g(15,4); s("%f",&Q3);

                gen_ave=(Q1+Q2+ Q3)/3;

                g(20,4); s("%f",&mid);
                g(30,4); s("%f",&aten) ;
                g(45,4); agg=(gen_ave*.3 )+(mid*.6)+(ate n*.1);
                p("%.2f",agg) ;
                getch();

                clrscr();

                g(5,3); p("Q1");
                g(10,3); p("Q2");
                g(15,3); p("Q3");

                g(5,3); p("Q1");
                g(10,3); p("Q2");
                g(15,3); p("Q3");
                g(20,3); p("Final Term");
                g(30,3); p("Attendance") ;
                g(45,3); p("Over All Grade");

                g(5,4); s("%f",&fQ1);
                g(10,4); s("%f",&fQ2);
                g(15,4); s("%f",&fQ3);

                fgen_ave=(fQ1+f Q2+fQ3)/3;

                g(20,4); s("%f",&fmid) ;
                g(30,4); s("%f",&faten );

                g(45,4); fagg=(fmid*.6)+ (faten*.1)+(fge n_ave*.3);
                p("%.2f",fagg );

                getch();
                clrscr();

                g(5,3); p("Final Grade");
                b=agg*.40;
                a=fagg*.60;

                g(5,4);
                f=b+a;
                p("%.2f",f);
                }
                else if(choice==3)
                {
                clrscr();
                count=0;
                g(22,8); p("Enter A String: ");
                s("%s",&wrd);
                g(22,9);
                for(ctr=0;ctr=( strlen(wrd)-1);++ctr)
                {
                if(wrd[ctr]==letter)
                {
                count=count+1;
                }
                }
                p("Your letter is: ");
                p("%i",count) ;

                }
                getch();
                }

                Comment

                Working...