Click to See Complete Forum and Search --> : power function


sotito
March 28th, 2008, 03:46 PM
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.

Plasmator
March 28th, 2008, 03:52 PM
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.

GCDEF
March 28th, 2008, 03:53 PM
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.

sotito
March 28th, 2008, 03:57 PM
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;
}

Plasmator
March 28th, 2008, 03:59 PM
Did you even read what we posted? :rolleyes:

sotito
March 28th, 2008, 04:01 PM
Oooooh sorry about that, yeah i am just going take your advise and multiply by itself.... jeje sorry about that. Thanks for the help.