473,836 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

3 New Member
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 13112
Banfa
9,065 Recognized Expert Moderator Expert
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
lingjun
3 New Member
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 Recognized Expert Top Contributor
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
408
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 file please check your setup" It only appears when i'm using a p2p program called elephant,who needs framework to run.some month ago I instaled for first time elephant and framework,but i don't remember whar version of framework i had
2
497
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 below and the code below submits the data to the DB and redirects the user. The code works locally on http://localhost or http://127.0.0.1 but when I upload it to a site (I have tried a few and they all error) it says "An error occurred on the...
3
2948
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 information. This can occur, but I donot want to see this error page. In stead I want the program to show a standard form where I can tell that bla vla bla and try again later. In the ASP.NET configuration I can specify a URL in case of an error. But I'll...
2
9407
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 started to get this error when running through my queries: SQL30081N A communication error has been detected. Communication protocol being used: "TCP/IP". Communication API being used: "SOCKETS". Location where the error was detected:...
4
48804
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 type belpw Standard connection failed.
9
5314
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 this variable is not empty. The message is shown using the "alert()" function. The page works good in almost all the case, but some users have reported to my that the alert window don't appear.
1
45784
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
2260
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 not constant" issue. I had the code compiling earlier, but made the mistake of moving thing aorund without taking a backup and now nothing works! Any help would be greatly appreciated. /*=======================================================*/...
2
5178
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 EXPAND_CONCAT(name1,name2) name1 ## name2 105: #define CONCAT(name1,name2) EXPAND_CONCAT(name1,name2) 106: #define RT_MODEL CONCAT(MODEL,_rtModel)
0
9827
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9677
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10560
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10607
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9389
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6986
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5838
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4468
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.