View Single Post
  #2 (permalink)  
Old July 7th, 2018, 03:37 PM
Natured Natured is offline
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2018
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Bit of a mixup.

This seems to be a minor error, the code actually skips over the ++; operator entirely to get the desired result you can re-write this code with a simple change.

Code:
myNumber = 1;
myVar = (myNumber * 10 + 1);
myVar++;
This would yield the desired result. You can also place "++" on the Pre side instead of the Post side of the variable. (shown below)


Code:
myVar = (++myNumber * 10 + 1);
However this is interpreted as: 2 * 10 + 1 which is 21.

Hopefully this helps clear up any confusion.
Reply With Quote