CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: power function

  1. #1
    Join Date
    Mar 2008
    Posts
    9

    Question power function

    Hey there everyone.
    Well i am almost new to programing and right now i am working on a program which will tell me the area of all the shape known to man... well atleast all know in algebra 2. But right now i am kinda stuck with square's. I know to get the area of a square all i need is a side and put it to the power of 2. I heard from someone to do that all i need to do is put it like this:

    X^2

    but that isin't really working no matter how i try to put it. So can someone please show me an example of how to do that. I would apreciated if you would show me a full working program. Even if its really simple.

  2. #2
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: power function

    In C++ operator^ is bitwise xor.
    There is a function called std:: pow from the standard cmath header which you can use to compute this sort of thing.

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: power function

    If all you want to do is square something, just multiply it by itself. Otherwise, look up the pow function.

    The area of a rectangle, including squares is L x W, so in this case, that's probably a better way to go anyway.

  4. #4
    Join Date
    Mar 2008
    Posts
    9

    Re: power function

    Well here its a example to put a number to the power of 2, but it won't work:

    #include<iostream>
    #include<math.h>
    using namespace std;
    int main()
    {
    double a = 0.0;
    double b = 0.0;
    cout <<"Please enter the number you would like to " << endl;
    cout <<"put to the power of 2: " << endl;
    cin >> a;
    b = a^2;
    cout <<"the answer is: " << b << endl;
    system("pause");
    return 0;
    }

  5. #5
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: power function

    Did you even read what we posted?

  6. #6
    Join Date
    Mar 2008
    Posts
    9

    Re: power function

    Oooooh sorry about that, yeah i am just going take your advise and multiply by itself.... jeje sorry about that. Thanks for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured