Syntax Error Code in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deenar
    New Member
    • Sep 2010
    • 13

    Syntax Error Code in C

    Hi Guys, I'm getting an error msg of 'declaration syntax error' NEED HELP!!!
    Code:
    #include<stdio.h>
    #include<ctype.h>
    
    void PrintMenu()
    {
    	printf("a) My Name \n");
    	printf("b) Tutorial day and time \n");
    	printf("c) Enter Number \n");
    	printf("q) Quit \n");
    	
    	return;
    }
    
    char GetOption
    {
    	char option;
    	
    		scanf("%c%*c", &option);
    		option = tolower(option);
    		
    	return(option);
    }
    
    void Printname()
    {
    	printf("Name \n");
    	
    	return;
    }
    
    void PrintTut()
    {
    	printf("Tuesday 2.30pm \n");
    	
    	return;
    }
    
    void PrintNumber()
    {
    	printf("Enter Number:  \n");
    	scanf("%d%*c", &num);
    	if 
    		(num>=1 & num<=50)
    		for(i=0; i>=50; i++)
    		printf("%d ", i);
    	else
    		printf("Error! \n");
    		
    	return;
    }
    	
    void DoOption(char option)
    {
    	switch(option)
    	{
    		case 'a':
    			PrintName();
    			break;
    		case 'b':
    			PrintTut();
    			break;
    		case 'c':
    			PrintNumber()
    		case 'q':
    			break;
    		default:
    			printf("Please enter a valid option \n");
    	}
    }	
    
    int main()
    
    {
    	int num, i;
    	char option;
    	do
    	{
    		PrintMenu();
    		GetOption();
    		DoOption();
    		
    	}while(option!='q');
    	
    	return(0);
    }
    Thanks
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    1: "char GetOption" should be "char GetOption()" i.e missing brackets

    2: in PrintNumber() function, "num" and "i" is undeclare

    3: in DoOption method, semicolon is missing after case 'c' i.e. for PrintNumber() statement

    4: In main, DoOption() is called without any parameter, it expect single parameter

    Comment

    • ashitpro
      Recognized Expert Contributor
      • Aug 2007
      • 542

      #3
      1: "char GetOption" should be "char GetOption()" i.e missing brackets

      2: in PrintNumber() function, "num" and "i" is undeclare

      3: in DoOption method, semicolon is missing after case 'c' i.e. for PrintNumber() statement

      4: In main, DoOption() is called without any parameter, it expect single parameter

      Comment

      • deenar
        New Member
        • Sep 2010
        • 13

        #4
        Thanks so much!!!

        Comment

        • Oralloy
          Recognized Expert Contributor
          • Jun 2010
          • 988

          #5
          @deenar,

          We have no problem helping at all.

          Next time, though, will you be kind enough to provide the exact error messages - it helps a lot when working these sorts of problems.

          Also, and I'm being "subtle" here - read the error messages and try to figure out what they mean. Most compilers tell you line number and some kind of indicator of what happened. It'll sure save you a lot of time, next time you need to get some code working.

          Cheers!
          Oralloy

          Comment

          • deenar
            New Member
            • Sep 2010
            • 13

            #6
            Sorry i'm new to all this but def if i need help i'll put the error msgs as well. I had looked at the error on the line and it said i was missing a syntax error on line 22 which was just 'return;'. Thanks anyway...

            Comment

            Working...