I asume you want to use ^ for e.g. 4³ being 4*4*4?
if so thats not what ^ is used for in C++.
use pow instead:
Code:pow(5,2); //5 to the power of 2
Apparently the compiler does not understand my ^ character. Not sure why that is, even tho i already included the math.h header.Code:#include "stdafx.h" #include <iostream> #include <math.h> using namespace std; int main() { int x; int y; x = 1; y = (1 + (2/x) ) ^ (3 * x); cout << y; cin.get(); return 0; }
Anyone care to help?
BTW, how would a loop be used in order to find values of Y from x = 0-100?
I asume you want to use ^ for e.g. 4³ being 4*4*4?
if so thats not what ^ is used for in C++.
use pow instead:
Code:pow(5,2); //5 to the power of 2
^ in C++ is a bitwise XOR. Also think it does something in MFC (Microsoft Foundation Classes), but who knows. =/
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
pow() pow() pow()
~
^_^ admitedly it's a bit annnoying but I'm not sure if you can overload bitwise operators, but you could try to see.
[php]
//note the syntax of opertaor overload is remenisant of any functions syntax
// <type> <name>(<operands>) int main(void) operator ^(&F, &S)
// we need the memory addresses for this to work like an actual operator
//which require the = sign
operator ^(<type> &F, <type> &S)
{
//code to work with operands F,S
}
operator ^(double, double);
operator ^(int, int);
int main()
{
int n;
n = 5^6;
....
......
}
[/php]
I considered the idea of writing it out for you, but operator overloading is something you should go learn about if you don't already know. I guess copying from code from the actual pow() function in the header would help. Operator overloading would also allow you to make a "better" version of
pow() since it only provides support for int values. Considering powers with double values would cause(many) inaccuracies it might be necessary that you have it truncate float values.
Also for versatility you might having to run into the OOP idea of templates.
Last edited by Arhk; 04-04-2010 at 08:13 AM.
"If the world hates you, keep in mind that it hated me first." John 15:18