Basic questions

Posts 1–4 of 4 · Page 1 of 1
Basic questions
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;
}
Apparently the compiler does not understand my ^ character. Not sure why that is, even tho i already included the math.h header.

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. =/
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.
Posts 1–4 of 4 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?