Oh, but of course the statement changes if you add parentheses. Basically, you’re changing the effective numbers that are being used, because the parentheses act as containers with a given value (you even showed the effective numbers in your examples).
Get this : + 1 - 1 + 1 - 1 + 1 - 1 + 1
You can change the result several times by choosing where you want to put the parentheses. However, the order of operations of same priority inside a container (parentheses) does not change the resulting value of the container.
In the example, there were no parentheses, so no ambiguity (there wouldn’t be any ambiguity with parentheses either, the correct way of calculating would just change), and I don’t think you can add “ambiguity” by adding parentheses — you’re just changing the effective expression to be evaluated.
By the way, this is the reason why I absolutely overuse parentheses in my engineering code. It can be redundant, but at least I am SURE that it is going to follow the order that I wanted.
SmartmanApps@programming.dev 1 day ago
No it doesn’t. You disobeying the rules and getting lots of wrong answers in your examples doesn’t change that.
Which you did wrong.
And I’ll show you it doesn’t matter when you do it correctly
Nope. Right answer for wrong reason - you only co-incidentally got the answer right. -3+1+2+4=-3+7=4
Nope. 4-3+2+1=1+2+1=3+1=4
Or you could just do it correctly in the first place, always obeying Left Associativity and never adding Brackets
There aren’t ANY ambiguous cases. In every case it’s equal to 4. If you didn’t get 4, then you made a mistake and got a wrong answer.