Thread: Quick question about invalid operands!

  1. #1
    Registered User
    Join Date
    Oct 2007

    Quick question about invalid operands!

    Working on a program right now but I left my book at home so I can't look this up. Does anyone know how to fix this off the top of their head? I was thinking about using 'atoi' but I can't remember how it works exactly.

    "invalid operands of types `double' and `double' to binary `operator^' "

    is what is says to me. :[

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    ^ is bitwise XOR, which I imagine you may have been thinking is the way to raise a number to an arbitrary power. If that is the case, use the pow() function in math.h.

    atoi() has nothing to do with this, and is a rather silly suggestion. Don't confuse strings with math or bitwise operations.

    If you are trying to bitwise XOR two doubles, whatever you're doing is probably very weird and wrong.

  3. #3
    Join Date
    Oct 2007
    Inside my computer
    	float f1 = 1.0f, f2 = 2.0f, f3;
    	double d1 = 1, d2 = 2, d3;
    	int i1 = 1, i2 = 2, i3;
    	f3 = f1 | f2; // C2296 and C2297
    	d3 = d1 | d2; // C2296 and C2297
    	i3 = i1 | i2;
    	f3 = f1^f2; // C2296 and C2297
    	d3 = d1^d2; // C2296 and C2297
    	i3 = i1^i3;
    Why you ask? Type must be an integer, not a floating point.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    I don't think operator^ is what you think it is, unless you want to bitwise-XOR two doubles together. atoi takes a string and returns the integer it represents.

    I'm guessing you want to raise to a power? If so, use pow().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM