Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help compiling else if statements.

Posted on 1999-07-31
5
Medium Priority
?
527 Views
Last Modified: 2013-12-05
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);      

     }
0
Comment
Question by:scully12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1264139
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
 
LVL 84

Expert Comment

by:ozo
ID: 1264140
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
 

Author Comment

by:scully12
ID: 1264141
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
 
LVL 6

Accepted Solution

by:
Triskelion earned 150 total points
ID: 1264142
//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
 

Author Comment

by:scully12
ID: 1264143
Thanks Triskelion that appears to be doing the job.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question