jugivi:
I want to multiply a variable by -1 (minus 1), to pass the value from negative to positive...
variable1 = variable2 * -1;
but I get a compilation error (unexpected token), is there another way to do this?.
Thank you.
I want to multiply a variable by -1 (minus 1), to pass the value from negative to positive...
variable1 = variable2 * -1;
but I get a compilation error (unexpected token), is there another way to do this?.
Thank you.
Did you try . . .
variable1 = -1 * variable2;
. . . ?
A minus sign - is an operator . . .
so your code executes the multiplication first due to precedence rules . . . and variable2 * - doesn't make much sense to the compiler as you are trying to multiply a variable by an operator.
My code does this first, 1 * variable2 and then applies the "Changing the operation sign" - to the result so it works. You could also do this . . . variable1 = variable2 * (-1);
Changing the operation sign x = - x;
so your code executes the multiplication first due to precedence rules . . . and variable2 * - doesn't make much sense to the compiler as you are trying to multiply a variable by an operator.
My code does this first, 1 * variable2 and then applies the "Changing the operation sign" - to the result so it works. You could also do this . . . variable1 = variable2 * (-1);
Thanks
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
variable1 = variable2 * -1;
but I get a compilation error (unexpected token), is there another way to do this?.
Thank you.