Thread: Illegal Operand

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    33

    Illegal Operand

    Code:
    Drag = 0.5*p*v^2*A*Cd/100;
    the nature of this calculation isnt important, but what is important is that when this is compiled, I get an error saying

    '^': Illegal, left operand has type 'double'

    How do I stop this? every number is of the long type, v is not double.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Use the function pow for exponentiation -- ^ is the exclusive OR operator.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    33
    Now my compiler says that the identifier pow could not be found.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    #include <cmath>
    using std::pow;
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Or, if you code that works with C or C++
    Code:
    #include <math.h>

  6. #6
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    Posts
    174
    Quote Originally Posted by grumpy
    Or, if you code that works with C or C++
    Code:
    #include <math.h>
    Or if you want code that will continue to work as C or C++:
    Code:
    #if defined(__cplusplus)
      #include <cmath>
      using std::pow;
    #else
      #include <math.h>
    #endif
    Ya, we all know that even though the .h C headers are deprecated, they won't be removed in the forseeable future. But I felt the need to mention it to placate the standards gestapo on this forum.
    Just because I don't care doesn't mean I don't understand.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  2. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 03:53 PM
  3. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  4. illegal operand with & operator
    By Mr_Jack in forum C++ Programming
    Replies: 1
    Last Post: 04-15-2004, 08:26 AM
  5. illegal operand
    By monkey_C in forum C Programming
    Replies: 8
    Last Post: 09-12-2002, 05:53 PM