By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,601 Members | 1,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,601 IT Pros & Developers. It's quick & easy.

where can i found my declaration syntax error?

P: n/a
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. void main()
  3. {
  4. char choice;
  5. int month,sum,num,i,a,b;
  6. int age,kasarian;
  7. char ans;
  8. int e,c,d;
  9. int num1,num2,diff,prod;
  10. clrscr();
  11.  
  12.        main_menu:
  13.        {
  14.        printf("          ++++++MAIN_MENU+++++\n");
  15.        printf("          +  [1]   if        +\n");
  16.        printf("          +  [2]   switch    +\n");
  17.        printf("          +  [3]   for loop  +\n");
  18.        printf("          +  [4]   exit      +\n");
  19.        printf("          ++++++++++++++++++++\n");
  20.        printf("enter your choice:");
  21.        scanf("%d",&choice);
  22.        clrscr();
  23.      if(choice=='1')
  24.        {
  25.        if_program:
  26.        printf("        *#*#*#*#*#*#*#*#*#*#*#*#*\n");
  27.        printf("        *       [A] age         *\n");
  28.        printf("        *       [b] mdas        *\n");
  29.        printf("        *#*#*#*#*#*#*#*#*#*#*#*#*\n");
  30.        printf("Enter Your choice:");
  31.        scanf("%s",&choice);
  32.  
  33.      if((choice=='A')||(choice=='a'))
  34.     {
  35.      printf("enter your age:\n");}
  36.      scanf("%d",&age);
  37.     if(age>=0 && age<=2)
  38.      {printf("still a baby",age);}
  39.     else if(age>=3 && age<=12)
  40.     { printf("children",age);}
  41.     else if(age>=13 && age<=17)
  42.     { printf("teenager",age);}
  43.     else if(age>=18 && age<=26)
  44.      {printf("young adult",age);}
  45.     else if(age>=27 && age<=39)
  46.     { printf("middle age",age); }
  47.     else if(age>=40 && age<=79)
  48.      {printf("grand parents",age);}
  49.     else
  50.      {printf("higher",age);}
  51.  
  52.  
  53.      printf("do u want to run another if_program?'Y'/'N'");
  54.      scanf("%s",&ans);
  55.      if((ans=='Y')||(ans=='y'))
  56.  
  57.      {goto if_program;}
  58.  
  59.       }
  60.       }
  61.      if(choice=='B')
  62.      {
  63.      printf("   !!!!!!!!!!!!!!!!!!!!!!!!\n");
  64.      printf("   !! [1] addition       !!\n");
  65.      printf("   !! [2] subtraction    !!\n");
  66.      printf("   !! [3] multiplication !!\n");
  67.      printf("   !!!!!!!!!!!!!!!!!!!!!!!!\n");
  68.      printf("enter your choice:");
  69.      scanf("%d",&choice);
  70.         if(choice==1)
  71.       {
  72.        printf("addition");
  73.        printf("enter the first number:");
  74.        scanf("%d",&num1);
  75.        printf("enter the second number:");
  76.        scanf("%d",&num2);
  77.  
  78.        sum = num1 + num2;
  79.        printf("The sum of two numbers is:%d",sum);
  80.       }
  81.      else if(choice==2)
  82.      {
  83.        printf("subtraction:");
  84.        printf("enter the first number:");
  85.        scanf("%d",&num1);
  86.        printf("enter the second number");
  87.        scanf("%d",&num2);
  88.  
  89.        diff= num1 - num2;
  90.        printf("the difference of two numbers is:%d",diff);
  91.       }
  92.       else
  93.       {
  94.         printf("multiplication");
  95.         printf("enter the first number");
  96.         scanf("%d",&num1);
  97.         printf("enter the second number");
  98.         scanf("%d",&num2);
  99.  
  100.         prod=num1 * num2;
  101.         printf("the product of two numbers is:%d",prod);
  102.       }
  103.  
  104.      printf("GO BACK TO MAIN MENU?'Y'/'N'");
  105.      scanf("i",&ans);
  106.      if((ans=='Y')||(ans=='y'))
  107.      {goto main_menu;}
  108.  
  109.       }
  110.       }
  111.       if(choice=='2')
  112.      {
  113.      switch_program:
  114.  
  115.      printf(" #####################\n");
  116.      printf(" ##  [W]  kasarian  ##\n");
  117.      printf(" ##  [Z]  animals   ##\n");
  118.      printf(" #####################\n");
  119.      printf("enter your choice");
  120.      scanf("%s",&choice);
  121.      switch(choice);
  122.  
  123.      if(choice=='W')
  124.  
  125.      {
  126.       printf("ienter ang iyong kasarian:");
  127.       scanf("%s",&kasarian);
  128.       switch(kasarian)
  129.       {
  130.         case 'a' : case 'A':
  131.       {
  132.        printf("ikaw ay BABAE");
  133.        break;}
  134.         case 'b' : case 'B':
  135.        {
  136.         printf("ikaw ay LALAKI");
  137.         break;}
  138.          case 'c': case 'C':
  139.        {
  140.         printf("sa kang BAKLA");
  141.         break;}
  142.           case 'd': case 'D':
  143.        {
  144.         printf("TOMBOY ka pre");
  145.         break;}
  146.         default:
  147.  
  148.       {
  149.       printf("invalid:");
  150.  
  151.       printf("do yOU want to run another switch program:?'Y'/'N'");
  152.       scanf("%s",&ans);
  153.       if((ans=='Y')||(ans=='y'))
  154.       {goto switch_program;}
  155.      }
  156.     }
  157.      else if(choice=='Z')
  158.      {
  159.       printf("          $$$$$$$$$$$$$$$$$$$$\n");
  160.       printf("          $$    [1] dog     $$\n");
  161.       printf("          $$    [2] cat     $$\n");
  162.       printf("          $$    [3] mouse   $$\n");
  163.       printf("          $$$$$$$$$$$$$$$$$$$$\n");
  164.       scanf("%s",&choice);
  165.       switch(choice);
  166.       {
  167.        case 1:
  168.  
  169.        {printf("the dog is the biggest");
  170.          break;}
  171.        case 2:
  172.        {printf("the cat is the medium");
  173.          break;}
  174.        case 3:
  175.        {printf("the mouse is the smallest");
  176.  
  177.        printf("do you want to run another program?'Y'/'N'");
  178.        scanf("s",ans);
  179.        if((ans=='Y') || (ans=='y'))
  180.        {goto main_menu;}
  181.      }
  182.      }
  183.        }
  184.        }
  185.       if(choice=='3')
  186.       { loop_program:
  187.        printf("  ::::::::::::::::::::\n");
  188.        printf("  :::  [E] sum     :::\n");
  189.        printf("  :::  [F]         :::\n");
  190.        printf("  ::::::::::::::::::::\n");
  191.        printf("enter your choice");
  192.        scanf("s",&choice);
  193.        if (choice=='E')
  194.        {
  195.         for(e=1;e<=1;e++)
  196.         {printf("$");
  197.         printf("\n");
  198.         for(c=1;c<=2;c++)
  199.         printf("$");
  200.         printf("\n");
  201.         for(d=1;d<=3;d++);
  202.         }
  203.  
  204.     }
  205.        else
  206.        {printf("invalid choice");}
  207.  
  208.    }
  209. getch();
  210. }
Oct 18 '10 #1
Share this Question
Share on Google+
2 Replies


Meetee
Expert Mod 100+
P: 931
Can you please post the error message also? I think, it would be always helpful to describe a problem.
Oct 18 '10 #2

100+
P: 687
Closing brace on line 110 corresponds to open brace at line 3 - the body of main() function, so it refuses to parse 'if' operator outside the function body. It's not surprising you messed up the braces given that this code is a unstructured mess of ifs and elses.
Oct 18 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.