Thread: invalid operands to binary ^ ?

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    38

    invalid operands to binary ^ ?

    What is wrong with this? cant figure it out... perhaps the square sign i'm using is the wrong square sign?

    Code:
    #include <stdio.h>
    int main ()
    
    {
        double m;
        double n;
        double side1;
        double side2;
        double hypo;
        
        printf ("Enter the side of n\n");
        scanf ("%lf", &n);
        printf ("Now enter the side of m\n");
        scanf ("%lf", &m);
        side1 = m^2 - n^2;
        printf ( "Side 1 is" );
        printf ("%lf", side1);
    
    return 0
    }
    the program isnt done, but i thought i check that 1st part, and keep getting the error

    15 C:\Documents and Settings\Emir\Desktop\C\Class\triangle.c invalid operands to binary ^

    ?

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    ^ is bitwise XOR not power

    To correct it:
    #include <math.h>
    and use pow()

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    38
    Quote Originally Posted by Thantos
    ^ is bitwise XOR not power

    To correct it:
    #include <math.h>
    and use pow()

    ok lemme try

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    38
    how do i use the pow?

    i did

    Code:
        side1 = m pow(2) - n pow(2);
    i dunno how to use pow

  5. #5
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    From a maths point of view, I don't understand that code, but assuming you are using ^ to mean "power", then you wanted:
    Code:
    #include <stdio.h>
    #include <math.h>
    int main ()
    
    {
        double m;
        double n;
        double side1;
        double side2;
        double hypo;
    
        printf ("Enter the side of n\n");
        scanf ("%lf", &n);
        printf ("Now enter the side of m\n");
        scanf ("%lf", &m);
        side1 = pow(m, 2.0) - pow(n,2.0);
        printf ( "Side 1 is" );
        printf ("%lf", side1);
    
        return 0;
    }
    The ^ operator has nothing to do with powers, it's the bitwise exlusive or operator.

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Quote Originally Posted by seal
    how do i use the pow?

    i did

    Code:
        side1 = m pow(2) - n pow(2);
    i dunno how to use pow
    Use the google n00b

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Use the google n00b
    But I searched for 'pow' and all I got were a lot of cheesy references to the Batman TV series
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Aug 2005
    Posts
    38
    Quote Originally Posted by Thantos
    Use the google n00b
    last time i checked this was a msg board for programming, and it doesnt say no basic questions allowed

  9. #9
    Registered User
    Join Date
    Aug 2005
    Posts
    38
    Quote Originally Posted by Salem
    > Use the google n00b
    But I searched for 'pow' and all I got were a lot of cheesy references to the Batman TV series
    actually you would get alot of references to POW as in prisoner of war...

  10. #10
    Registered User
    Join Date
    Aug 2005
    Posts
    38
    Quote Originally Posted by cwr
    From a maths point of view, I don't understand that code, but assuming you are using ^ to mean "power", then you wanted:
    Code:
    #include <stdio.h>
    #include <math.h>
    int main ()
    
    {
        double m;
        double n;
        double side1;
        double side2;
        double hypo;
    
        printf ("Enter the side of n\n");
        scanf ("%lf", &n);
        printf ("Now enter the side of m\n");
        scanf ("%lf", &m);
        side1 = pow(m, 2.0) - pow(n,2.0);
        printf ( "Side 1 is" );
        printf ("%lf", side1);
    
        return 0;
    }
    The ^ operator has nothing to do with powers, it's the bitwise exlusive or operator.

    thx for showing me how to use pow ()

  11. #11
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    Quote Originally Posted by seal
    thx for showing me how to use pow ()
    Before googling try to use help function provided in your compiler.
    you will get everything instantly.If help is not there in it.then best of luck for next time

  12. #12
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Quote Originally Posted by seal
    last time i checked this was a msg board for programming, and it doesnt say no basic questions allowed
    Actually we do want you to do the work. There is a SEARCH feature on this message board and on google. Use them.

    Quote Originally Posted by seal
    actually you would get alot of references to POW as in prisoner of war...
    only if you are stupid enough to just use "pow" as your search. If you notice my search had a lot more then just pow

  13. #13
    Registered User
    Join Date
    Aug 2005
    Posts
    38
    Quote Originally Posted by Thantos
    Actually we do want you to do the work. There is a SEARCH feature on this message board and on google. Use them.


    only if you are stupid enough to just use "pow" as your search. If you notice my search had a lot more then just pow
    i was comparing 'pow' to batman pow not the pow ()

    could have told me how to use it and saved us alot of trouble but oh well, thx for the help that u've provided

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1) You obviously have no sense of humor.
    2) You're apparently lazy, and would rather be given an answer than taught how to help yourself.
    3) Lazy humorless people annoy me.


    Quzah.
    Hope is the first step on the road to disappointment.

  15. #15
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    See salem was poking fun at me and being silly. Now I could have just told you exactly how to use pow but then what about next time? Hopefully now you'll know how to find the answer for yourself. Also considering that I gave you a link to a search page in which the very first result told you exactly what the fun did and how to use it, I think I did tell you how to use it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: invalid operands to binary *
    By cblix in forum C Programming
    Replies: 5
    Last Post: 01-29-2006, 08:45 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Need help with C program
    By ChrisH in forum C Programming
    Replies: 38
    Last Post: 11-13-2004, 01:11 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM