lets say i have 3 int arrays and are initiated like
int a[]={A,B,1,0};
int b[]={C,D,0,1};
int add[4];
int A,B,C,D;
with A,B,C,D declared as integers but not initiated.
in a for loop i add a and b arrays and store the results in array add...
of course when i try to print the elements of the add aray i see only the numerical values to be added and some kind of huge numbers in the first two elements....(i would like to know what do these huge numbers represent)
So dont want to know the values of A,B,C,D nor their sum but i would like to have as a result from their addition an Alpharithmetic(A or B or C or D) or an integer....
for example i would like to declare
A+B=C
A+C=1
B+C=0
B*D=A
C*A=B
or any other combination of multiplication and addition
the compailer does not accept expresions like
A+B=1;or C+B=D; without initialized the values of variables first
i was wondering if that could be done usin the enum
What you asking to do is not part of a procedural language mindset. You are thinking more along the lines of a functional programming language like Haskell.
2nd: The huge numbers you are seeing is uninitialized memory that has been allocated for your variables.
You cannot add A to B because A and B have no values. Therefore you end up with an invalid number. You are unable to say "C = A + B". C Must have a real value if it's going to be a normal type.
You COULD smoke and mirrors (thnx bnbertha) this. But it'd require you developing a bunch of classes that took pointers to real variables and performed a function on them, returning (through operator overloading) the value you asked for. But even then it'd need REAL numbers to work with.
One other thing with using #define
It's a preprocessor directive and is therefore global scope. They can cause weird compile and runtime problems unless you use very specific macro names.
first of all i would like to thank you for your answers.....
I knew i could not do what i wanted.....but i hoped for the existance of any way to do this i might not know.....the truth is that these alpharithmetics do represent integer trains but that is the hard way for what i want to do.....anyway
something else...is there a way when printing an int array instead of getting the address of the alpharithmetics to just get the alpharithmetic character on my screen?and if not is there any array type that could work as an int and char array at the same time.....
what i meen is to have the ability to make numerical calculations and also have the ability to print the alpharithmetic chars as they are without conversion of the array type....
Mann: please create your own topic instead of hi-jacking others.
Zourlas: Ok, You CAN actually do what you wish to achieve. However, this would require a complete object-orientated parent-child hierarchy. You would need to define your own type and then sub-types.
E.g. SubType "Add" would take pointers to 2 other classes and add the values together on the fly when asked for the result.
This would require some careful planning, but it's actually possible to do it using a lazy execution pattern.
As for your last reply, You shouldn't ever get the address of the int but the value. The reason it looks like you are getting an address is because you have not initialized your int to something. When you create a new int (and don't give it a value) it will have some memory assigned for it to store it's value. The OS/Compiler does not ensure this memory is cleared before it's given to you. This is why you end up with strange values. You need to give you int's an initial value (e.g int A = 0; to ensure you don't end up with unexpected values.
e.g.
1 2 3 4 5 6
int A[] = {0, 1, 2};
for (int i = 0; i < 3; ++i)
cout << "Value " << (i+1) << " = " << A[i] << endl;
int B[] = newint[10]; // All may contain invalid values.
memset(B, 0, 10); // Set all 10 Elements to 0
Bump. Just bumping this because I got asked how to do something similar at work. Weird how people want to emulate the functionality of a functional language in a procedural language.