bwjones

Can someone inform me on what the "-=" function does? thanks.

Aia 1,977

Can someone inform me on what the "-=" function does? thanks.

It is not a function is an arithmetic operator and assignment operator short cut.
number -= x;
same as
number = number - x;

bwjones

ahh i c. So rem-=50 is rem = rem-50? and rem+=50 = rem=rem+50? I'm a complete noob to programming and with an instructor who assumes the class is on his level when 3/4 isn't learning all this from scratch is a bit intense so I might show up with stupid questiosn from time to time. Thanks.

VernonDozier 2,218

ahh i c. So rem-=50 is rem = rem-50? and rem+=50 = rem=rem+50? I'm a complete noob to programming and with an instructor who assumes the class is on his level when 3/4 isn't learning all this from scratch is a bit intense so I might show up with stupid questiosn from time to time. Thanks.

Yes, that's what rem -= 50 and rem += 50 are.

jephthah 1,888

and here's a bunch more:

``=     +=     -=     *=     /=     %=     <<=     >>=     &=     ^=     |=``

"a *= 4 " is the same as "a = a * 4"
"b <<= 1" is the same as "b = b << 1".

in other words, multiply 'a' by 4 and put the result back in 'a'. ... shift 'b' left by one bit, and put the result back into 'b'.

one main thing to be aware of is "operator precedence". any statement that has more than one operator, the order of operations is strictly defined. so in C/C++, the following two expressions are the same:

ans = a + b * c;

ans = a + ( b * c );

but are completely different than

ans = ( a + b ) * c;

you can find a list of "operator precedence" most anywhere

.

WaltP 2,905

Gee guys, are we rewriting the text book? :icon_wink: