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

illegal indirection and syntax error.

im basically new to c programming, i wrote a code to work out a simple formula - t=R*C*ln(VC/(VC-VS)) however i keep getting illegal indirection and syntax error.
Here is the code

#include "assignment 1.h"
#define R 2;
#define C 2;
#define VS 50;
#define VC 33;
double t,a,b,c,d;


int main(void)
{
a=R*C;
c=VC-VS;
d=VC/c;
b=log(d);
t=a*b;
printf ("%d"), t;
system ("PAUSE");
return 0;

}

i have included in the header file the iostream library and the math library, looking at the code i cant find anything wrong with it.
PLEASE HELP!
Dec 14 '10 #1

✓ answered by donbock

In the future, please enclose your code snippets in CODE tags. That provides line numbers that make it easier to refer to specific parts of your code.
  1. Since you intend to use only floating-point math, it would be helpful if you used floating-point constants. This is accomplished by having a decimal point in the constant. For example:
    Expand|Select|Wrap|Line Numbers
    1. #define R 2.0
  2. Macros provide simple text replacement. For example, your macro definition for C means that each occurrence of "C" in your program is replaced by "2;" This is what your program looks like after macro replacement:
    Expand|Select|Wrap|Line Numbers
    1. double t,a,b,c,d;
    2. int main(void)
    3.    {
    4.    a=2;*2;;
    5.    c=33;-50;;
    6.    d=33;/c;
    7.    b=log(d);
    8.    t=a*b;
    9.    printf ("%d"), t;
    10.    system ("PAUSE");
    11.    return 0;
    12.    }
    Notice all of the extra semicolons in lines 4-6. They should not be there. The basic rule is NEVER put semicolons in macro definitions. There are occassional exceptions, but not for a new programmer.
  3. Look at your call to printf. Variable t should be inside the parentheses so it is passed to the printf function.
  4. Look at your call to printf. Your format string ("%d") is not compatible with the type of variable t.
By the way, your illegal indirection occurs on line 4. That error should go away when you take out the semicolons in your macro definitions.

2 2679
donbock
2,426 Expert 2GB
In the future, please enclose your code snippets in CODE tags. That provides line numbers that make it easier to refer to specific parts of your code.
  1. Since you intend to use only floating-point math, it would be helpful if you used floating-point constants. This is accomplished by having a decimal point in the constant. For example:
    Expand|Select|Wrap|Line Numbers
    1. #define R 2.0
  2. Macros provide simple text replacement. For example, your macro definition for C means that each occurrence of "C" in your program is replaced by "2;" This is what your program looks like after macro replacement:
    Expand|Select|Wrap|Line Numbers
    1. double t,a,b,c,d;
    2. int main(void)
    3.    {
    4.    a=2;*2;;
    5.    c=33;-50;;
    6.    d=33;/c;
    7.    b=log(d);
    8.    t=a*b;
    9.    printf ("%d"), t;
    10.    system ("PAUSE");
    11.    return 0;
    12.    }
    Notice all of the extra semicolons in lines 4-6. They should not be there. The basic rule is NEVER put semicolons in macro definitions. There are occassional exceptions, but not for a new programmer.
  3. Look at your call to printf. Variable t should be inside the parentheses so it is passed to the printf function.
  4. Look at your call to printf. Your format string ("%d") is not compatible with the type of variable t.
By the way, your illegal indirection occurs on line 4. That error should go away when you take out the semicolons in your macro definitions.
Dec 14 '10 #2
that worked brilliant, thank you very much :)
Dec 23 '10 #3

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

Similar topics

1
by: Steve | last post by:
I just spent waaaaaaaaaaaayy too much time trying to track down an error that was incorrectly reported just now, and I would like to see if someone can explain to me why it was reported that way. ...
1
by: Donald Canton | last post by:
Hi, I'm using Bjarne's book to learn C++ and am stuck on the Calc program in Section 6. Everything works fine except when I try to use istringstream to parse a token from the command line. I...
6
by: Andy White | last post by:
template <class Type> class Array { public: explicit Array(int size = DefaultArraySize); Array(Type *array, int array_size); Array(const Array &rhs); virtual ~Array() {delete ia;}
5
by: r.nikhilk | last post by:
Hi, Currently, we are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by...
2
by: david | last post by:
Anyone could give me a hand about this syntax error? Thank you. David Source Code: Dim conn As New SqlConnection(strConn) Dim daAngio As New SqlDataAdapter(strSelectStatement, conn) 'Create a...
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
6
by: curious2007 | last post by:
in matrixsolvermechanisms.hpp I have the following: template <class V, class I> class LUTridiagonalSolver { ... void calculateBetaGamma(); } Then in matrixsolvermechanisms.cpp I have the...
2
by: Lambda | last post by:
The code is simple: // Token.h #ifndef TOKEN_H #define TOKEN_H #include <vector> #include <string> class Token
14
by: Mike Copeland | last post by:
I'm getting a syntax error on the "typedef" code line here. Any thoughts on why? TIA struct CSTYPE { // City/State Record string csKey; ...
6
by: muby | last post by:
Hi everybody :) I'm modifying a C++ code in VC++ 2005 my code snippet void BandwidthAllocationScheduler::insert( Message* msg, BOOL* QueueIsFull,
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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: 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)...
0
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....

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.