Problem with simple case statements

This is a discussion on Problem with simple case statements within the C Programming forums, part of the General Programming Boards category; Hi, im trying to enter a couple of ints into a function and increment the value of the output depending ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    108

    Question Problem with simple case statements

    Hi, im trying to enter a couple of ints into a function and increment the value of the output depending on the value of the input.

    The two input values are a set of int which have to be transformed into a value of absolute seconds by the program. It will then check the program and if the value falls between a couple of "epochs" will increments as required.

    So far, i get a load of:

    error C2051: case expression not constant
    errors. can someone tell me what im doing wrong and a possible solution?

    The relevent section of my code, is below:

    thanks

    Code:
                double abs_GPS;
    
            time_t current;
            
    
            struct tm* loctime;
    
            abs_GPS = ((604800 * RX_WEEK) + (GPS_SEC)); /* convert to absolute GPS time	*/
    
    		current = (abs_GPS + 315964800);           /* Add absolute GPS time to the UTC epoch  */
    
    		/*The below case statements determine the time which the GPS relates to and adds any leap seconds that are needed */
    
    		switch (current)
    			{ 
                case current <= 46915200:  current = current + 1;				/* Add one leap second */
    					break;
    
                case  ((current >= 46915201) && (current =< 78451200)):  current = current + 2;	/* Add two leap seconds */
    					break;
    
                case  ((current >= 78451201) && (current =< 109987200)):  current = current + 3;	/* Add three leap seconds */
    					break;
    
                case  ((current >= 109987201) && (current =< 173145600)):  current = current + 4;	/* Add four leap seconds */
    					break;
    
                case  ((current >= 173145601) && (current =< 252115200)):  current = current + 5;	/* Add five leap seconds */
    					break;
    
    			case  ((current >= 252115201) && (current =< 315273600)):  current = current + 6;	/* Add six leap seconds */
    					break;
    
    			case  ((current >= 315273601) && (current =< 346809600)):  current = current + 7;	/* Add seven leap seconds */
    					break;
    
    			case  ((current >= 346809601) && (current =< 394070400)):  current = current + 8;	/* Add eight leap seconds */
    					break;
    
    			case  ((current >= 394070401) && (current =< 425606400)):  current = current + 9;	/* Add nine leap seconds */
    					break;
    
    			case  ((current >= 425606401) && (current =< 457228800)):  current = current + 10;	/* Add ten leap seconds */
    					break;
    
    			case  ((current >= 457228801) && (current =< 504662400)):  current = current + 11;	/* Add eleven leap seconds */
    					break;
    
    			case  ((current >= 504662401) && (current =< 551923200)):  current = current + 12;	/* Add twelve leap seconds */
    					break;
    
    			case  ((current >= 551923201) && (current =< 599356800)):  current = current + 13;	/* Add thirteen leap seconds */
    					break;
    
    			case  ((current >= 599356801) && (current =< 820195200)):  current = current + 14;	/* Add fourteen leap seconds */
    					break;
    
    			case  current >= 820195201:  current = current + 15;	/* Add fifteen leap seconds */
    					break;
    
    
    
    			}

  2. #2
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    >>error C2051: case expression not constant

    Listen to your compiler - switch statements are great for menus,
    but they are not as powerful as if/else blocks - you'll have to
    change your code to such a sequence for this type of program
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    108
    thanks.

    IŽll try if with if/else statements then

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04:42 PM
  2. Can someone please clean up my code
    By ki113r in forum C Programming
    Replies: 10
    Last Post: 09-12-2007, 10:03 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Keypress reading
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 06-16-2004, 12:16 PM
  5. error with code
    By duffy in forum C Programming
    Replies: 8
    Last Post: 10-22-2002, 09:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21