illegal indirection and syntax error.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • James Thomas
    New Member
    • Dec 2010
    • 2

    #1

    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!
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    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:
      Code:
      #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:
      Code:
      double t,a,b,c,d;
      int main(void)
         {
         a=2;*2;;
         c=33;-50;;
         d=33;/c;
         b=log(d);
         t=a*b;
         printf ("%d"), t;
         system ("PAUSE");
         return 0;
         }
      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.

    Comment

    • James Thomas
      New Member
      • Dec 2010
      • 2

      #3
      that worked brilliant, thank you very much :)

      Comment

      Working...