Help compiling else if statements.

I'm having trouble getting the code below to compile. If I only compile the first few lines of else if I'm fine but if I do the whole thing I get these errors:
test.c: In function 'main':
test.c:23: numeric constant contains digits beyond the radix
test.c:25: numeric constant contains digits beyond the radix
test.c:32: parse error before 'jd'
    I'm compiling with DJGPP if that matters. Am I formatting this wrong or is their a limit with how many else if lines of code I can do. I also tried a switch statement instead and got the same error.
my code:
#include <stdio.h>

main()
{
      
      int jd, jd1, jd2;
      int gd1, gd2, gd3;
      
     if (gd1 == 01)
     jd = gd2;
     else if (gd1 == 02)
     jd = (gd2 + 31);
     else if (gd1 == 03)
     jd = (gd2 + 59);
     else if (gd1 == 04)
     jd = (gd2 + 90);
     else if (gd1 == 05)
     jd = (gd2 + 120);
     else if (gd1 == 06)
     jd = (gd2 + 151);
     else if (gd1 == 07)
     jd = (gd2 + 181);
     else if (gd1 == 08)
     jd = (gd2 + 212);
     else if (gd1 == 09)
     jd = (gd2 + 243);
     else if (gd1 == 10)
     jd = (gd2 + 273);
     else if (gd1 == 11)
     jd = (gd2 + 304);
     else (gd1 == 12)
     jd = (gd2 + 334);      

     }
scully12Asked:
Who is Participating?
 
TriskelionConnect With a Mentor Commented:
//Please be sure to set the value of gd1 before the program
//  reaches the if statement.
//  The only problems with the original code are what ozo suggested and a missing if after the last else.
// Design may be a problem.  Check out the code below.

#include <stdio.h>
void main(void)
{
      static      int jd, jd1, jd2;
      static      int gd1, gd2, gd3;
      static int iaData[]={-1,0,31,59,90,120,151,181,212,243,273,304,334};
      if (gd1>0 & gd1 <13)
            {
            jd=(gd2+iaData[gd1]);
            }
}

0
 
AlexVirochovskyCommented:
Can be it is DJGPP limitation. Tray something as
  if (gd1  <= 6)
   {
      switch  (gd1)
        {
           case 1: ...; break;
           .....
        }
   }
 else
  {
    case 7: ... ; break;
   ....
  }
And i don't like 01/02/..
   use simple 1/2/...
0
 
ozoCommented:
09 is looks like an octal number because of the 0, but a decimal mumber because of the 9
Do you mean 011 or 9?
0
 
scully12Author Commented:
It's the decimal number 9. I don't remember why I did it like that orignally. I'm converting an old program from Pascal to C in an attempt to learn C. I just need a way to compile all these else if statements or a work around.
0
 
scully12Author Commented:
Thanks Triskelion that appears to be doing the job.
0
All Courses

From novice to tech pro — start learning today.