473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
3 13061
Banfa
9,065 Expert Mod 8TB
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
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
donbock
2,426 Expert 2GB
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

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

Similar topics

0
by: camaro77 majau via DotNetMonster.com | last post by:
Sorry by my english but i'm from spain. I have a problem and after search by the web i have know that is due by framework. The message is : setup error "failed to load ressouces from resource...
2
by: Luke | last post by:
Hi I have the following code which is an ASP questionnaire using an Access database. (I am using access as I have no choice!). Basically there is an html form which submits the form to the page...
3
by: ton | last post by:
Hi, I've developed some webcontrols in VB, I'm using these in a website project If the webcontrol is getting an error I ll get the message: Server error in '/' application, and than more...
2
by: Brent Halsey | last post by:
I am using the ibm_db2 PECL drive in PHP for connecting to or DB2 database. I created a persistent connection and things seemed to work fine at first. However, after a few tests / connections, I...
4
by: Pool | last post by:
I tried to connect DB2 (Sitting in Unix server at my client location) using Db2 connect V8. I am getting the following error message. I tried all the possible options BUt the error is same.. See each...
9
by: Tonio Tanzi | last post by:
I have an asp page with this tag <body onLoad="show_msg('<%=error_msg%>');"> where "show_msg" is a javascript function that shows the message contained in the asp variable "error_msg" only if...
1
by: Allen | last post by:
In my app, there is a namespace definition. .... namespace CMD { ... const int YT_UP = 1; // line 149 ... }; g++ tells expected unqualified-id before numeric constant error at
3
by: zoeb | last post by:
Hi, I am declaring an array which carries x coordinates, however these will vary depending on the geometry the user enters. I have set my code up as follows, but get the "initializer element...
2
by: tvnaidu | last post by:
I am getting this error for line 108, I kept C code also below, any idea?. main.c:108: underscore in number main.c:108: syntax error before numeric constant 104: #define...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.