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

How to fix "syntax error before numeric constant " error message?

P: 3
Hi,
I am taking my first programing course in college... and I am completely lost on this assignment. I am not sure what is wrong with my current code. Any help will be appreciate it... thanks!

I keep on getting the follow error messages when I try to compile it.

test.c:3: error: syntax error before numeric constant
test.c: In function `main':
test.c:18: error: `next_day' undeclared (first use in this function)
test.c:18: error: (Each undeclared identifier is reported only once
test.c:18: error: for each function it appears in.)
test.c: In function `find_next_day':
test.c:25: error: parameter name omitted
test.c:29: error: syntax error before "day"
test.c:32: error: break statement not within loop or switch
test.c:33: error: case label not within a switch statement
....
test.c:53: error: syntax error before "return"

My code is the following:
Expand|Select|Wrap|Line Numbers
  1.  
  2.  #include <stdio.h>
  3.  
  4. enum day {sun=1, mon, tue, wed, thur, fri, sat};
  5.  
  6. typedef enum day day;
  7.  
  8. day find_next_day (day);
  9.  
  10. int main(void)
  11. {
  12.     day x, next_day;
  13.  
  14.     printf("\nEnter a day. ");
  15.     scanf("%d", &x);
  16.  
  17.     find_next_day (x);
  18.  
  19.     printf ("%d", next_day);
  20.  
  21.     return 0;
  22. }
  23.  
  24.  
  25.  
  26. day find_next_day (day)
  27. {    
  28.     day next_day;
  29.  
  30.     switch (day) {
  31.     case sun:
  32.         next_day = mon;
  33.         break;
  34.     case mon:
  35.         next_day = tue;
  36.         break;
  37.     case tue:
  38.         next_day = sun;
  39.         break; 
  40.     case wed:
  41.         next_day = thur;
  42.         break;
  43.     case thur:
  44.         next_day = fri;
  45.         break;
  46.     case fri:
  47.         next_day = sat;
  48.         break; 
  49.     case sat:
  50.         next_day = sun;
  51.         break;
  52.     }
  53.  
  54.     return next_day;
  55.  
  56. }
  57.  
  58.  
Any help will be appreciated! Thanks.
Mar 18 '11 #1
Share this Question
Share on Google+
3 Replies


Banfa
Expert Mod 5K+
P: 8,916
You didn't get those errors from the code you posted so I suggest you either post the errors that match the code or post the code that matches the errors.
Mar 18 '11 #2

P: 3
Sorry. I rewrote the code with some changes. Now the only error message I am getting is:

testing.c:4: error: syntax error before numeric constant


My code is:
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3.  
  4. enum day {sun, mon, tue, wed, thur, fri, sat};
  5.  
  6.  
  7. typedef enum day Day;
  8.  
  9.  
  10. Day find_next_day (Day day);
  11.  
  12. int main(void)
  13. {
  14.    int error;
  15.    Day x, next_day;
  16.  
  17.     do {
  18.          printf("\n Please enter an integer for the starting day.  ");
  19.          scanf("%d", &x);
  20.          if (error = ( x> 6 || x < 0))
  21.              printf ("\n ERROR: The value must be within the range of 0 to 6.");
  22.          } while (error);
  23. /*The above should make sure the user enters a legit value*/
  24.  
  25.    next_day = find_next_day (x);
  26.  
  27.    printf ("%d", next_day);
  28.  
  29.    return 0;
  30. }
  31.  
  32.  
  33.  
  34. Day find_next_day (Day day) 
  35. /* I tried to take out the Switch and simplify it...*/
  36. {
  37.  
  38.     return ((Day) (((int) day +1) %7));
  39.  
  40. }
  41.  
  42.  
Mar 18 '11 #3

Expert 100+
P: 2,402
Lines 10, 34, and 38 use "day" as a variable, but that name has already been declared as an enum name on line 4.

Your error message points at line 4. I don't see anything wrong with that line.
Mar 18 '11 #4

Post your reply

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