By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,816 Members | 2,151 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,816 IT Pros & Developers. It's quick & easy.

illegal indirection and syntax error.

P: 2
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.

Share this Question
Share on Google+
2 Replies


Expert 100+
P: 2,398
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

P: 2
that worked brilliant, thank you very much :)
Dec 23 '10 #3

Post your reply

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