473,946 Members | 10,966 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Program won't compile: Declaration syntax error

4 New Member
I am a beginner at C++ and would be very grateful if someone could simply tell me why my program will not compile.

My program is as follows,

#include <stdio.h>

#define int 1ST VALUE = 23.0

void main()
{
float 2nd_value;
int 3rd_value, result:
printf("Enter a value:");
scanf("%c", 2nd_value;
result=(1ST_VAL UE+2nd_value)/3rd_value);
}

The only error is,

c(5,5): Declaration syntax error


I will be extremely grateful of any help, thank you.
Aug 7 '08 #1
7 4640
edwardrsmith
62 New Member
You are using macros incorectly. Instead of having
Expand|Select|Wrap|Line Numbers
  1. #define int var = 7
it should look like
Expand|Select|Wrap|Line Numbers
  1. #define var 7
When you use define, you are not creating a variable but marking something that the pre-compiler needs to take notice of. So when you compile the program, every instance of var that the pre-compiler runs accross it, it is replaced with 7.

If you want a tutorial go to google, type in #define and look at the third link.

Fixing that should take care of that error.

After you fix that, depending on the compiler, you may have problems with variable names starting with numbers.

Edward

P.S. When it comes to programming, google is your best friend.
Aug 7 '08 #2
Bowzer1999
4 New Member
I am not fully sure what you mean edward, could you please copy and paste the code i wrote with the correction then i can copy and paste that into C++ and hopefully ti will work, thanks
Aug 7 '08 #3
edwardrsmith
62 New Member
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. #define VALUE_1  23.0
  4.  
  5. void main(){
  6.      float value2;
  7.      int value3, result:
  8.      printf("Enter a value:");
  9.      scanf("%f", &value2);
  10.      result=((VALUE_1 + value2)/value3);
  11. }
There you go. I fixed a few other problems, such as using %c in scanf instead of %f and also changed the scanf line so it is passed a reference instead of a variable. I also changed the names so that they reflect a more apropriate naming style (one that should work on any compiler). Additionally I added the missing parantheses. Finally, I also changed the #define line so that it follows the apropriate style.

I would really suggest taking a look at this site. The specific page I linked to discusses macros and the rest of the site is an amazing resource for c/c++ programming. There are other ones out there but this is one of my two favorites.

Edward
Aug 7 '08 #4
Bowzer1999
4 New Member
Thanks very much, i will indeed look at that site, i will get back you if i have any more problems as you seem to have a lot of experience in progamming.

Rob
Aug 7 '08 #5
Laharl
849 Recognized Expert Contributor
Also, do not use void main(). main() returns an int, so use int main() and return 0 at the end of the function.

If you're really using C++, #include <cstdio>, not <stdio.h>, as that's the old (pre-1998) way (and you should probably be using <iostream> and namespace std anyway). If this is C, ignore that, as you're fine.
Aug 7 '08 #6
Bowzer1999
4 New Member
Could you please correct the coded i posted and post back to me this way i can compare it to the code i had and see exactly what needs changing, thanks.
Aug 7 '08 #7
weaknessforcats
9,208 Recognized Expert Moderator Expert
We can't do all your work.

Just look at any C++ textbook for a few minutes.
Aug 8 '08 #8

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

Similar topics

0
6168
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug file as folows. I need help to resolve them ASAP: cl /c /nologo /MDd /W3 /Od /GR /GM /Zi /GX /D "_DEBUG" /D " WIN32" /D "_W INDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /
27
3300
by: hpy_awad | last post by:
I wrote that program from a book that my compile that program correctly under C++ compiler but I got those errors for compiling under unix !! Errors- -------- part10_iti_r01_ch10_verbo_menu_driven_programs.c: In function `main': part10_iti_r01_ch10_verbo_menu_driven_programs.c:6: warning: declaration of `argc' shadows a parameter part10_iti_r01_ch10_verbo_menu_driven_programs.c:7: warning:
1
3086
by: steve smith | last post by:
Hi I have just downloaded the Borland C# Builder and the Micorsoft ..Net framework SDK v1.1 from the borland webist, and i am trying to get a simple program to run, however I keep getting errors, any ideas why this might be happening? Program i am running is: namespace ExamProblem { using System;
16
4843
by: Martin Joergensen | last post by:
Hi, I wanted to try something which I think is a very good exercise... I read in data from the keyboard and store them in a structure. There's a pointer called "data_pointer" which I use to keep track on the structures... But it's a bit confusing - my program won't compile and I don't know what to do about the warnings/error messages. c:\documents and settings\dell\Desktop\test\main.c(5) : warning
9
6931
by: ehabaziz2001 | last post by:
I am facing that error message with no idea WHY the reason ? "Abnormal program termination" E:\programs\c_lang\iti01\tc201\ch06\ownarr01o01 Enter a number : 25 More numbers (y/n)? y Enter a number : 30 More numbers (y/n)? n
20
2647
by: Francine.Neary | last post by:
I am learning C, having fun with strings & pointers at the moment! The following program is my solution to an exercise to take an input, strip the first word, and output the rest. It works fine when you give it 2 or more words, but when there's only 1 word the results vary depending on whether it's on Windows or Linux: under MSVC it displays no output (as it should); under gcc/Linux it instead gives "Segmentation fault". Any ideas...
2
3821
by: Warren Hoskins | last post by:
I'm going to have to break this up into files however I receiving errors when I try to compile this. I am confused about this program Please help.I.m using Visual C++ platform, XP operating system enclosed are the errors I'm getting and the code Vehicle.cpp Vehicle.cpp(35) : error C2511: 'Person::Person(Person &)' : overloaded member fu nction not found in 'Person' Vehicle.cpp(10) : see declaration of 'Person'
2
3039
by: d0ugg | last post by:
Hi, I'm doing a FRACTION program for one of my Programming classes and I'm getting some errors that I can't figure it out. Here is the Assignment: 1. Convert the fraction structure into a class named fraction declared in a file named fraction.h, with two private data members: an int numerator and an int denominator. 2. Convert the four arithmetic functions named add, sub, mult, and div into public member functions, each accepting a...
7
5789
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it compiled no problem. But I can't find the what the problem is with templates? Please help. The main is in test-linked-list.cpp. There are two template classes. One is List1, the other one is ListNode. The codes are below: // test-linked-list.cpp :...
0
11552
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11324
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
10679
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8240
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7403
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
6318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4928
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
4524
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3525
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.