473,323 Members | 1,622 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,323 software developers and data experts.

Program won't compile: Declaration syntax error

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_VALUE+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 4610
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
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
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
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 Expert 512MB
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
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 Expert Mod 8TB
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
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...
27
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- --------...
1
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,...
16
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...
9
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...
20
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...
2
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 ...
2
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...
7
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.