|
-
March 28th, 2008, 03:46 PM
#1
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.
-
March 28th, 2008, 03:52 PM
#2
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.
-
March 28th, 2008, 03:53 PM
#3
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.
-
March 28th, 2008, 03:57 PM
#4
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;
}
-
March 28th, 2008, 03:59 PM
#5
Re: power function
Did you even read what we posted?
-
March 28th, 2008, 04:01 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|