Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
You're doing it all wrong, even by BIMDAS standards:
5+4*3^2-1/2 --- original
5 + 4 * (3^2) -1/2 --- first step with Indices (the parenthesis was just my way to highlight this step.)
5 + 4 * 9 - 1/2 -- what we get after we solve that step.
5 + (4 * 9) - 1/2 -- the next step, where we do multiplication.
5 + 36 - 1/2 --- the result from that step
5 + 36 - (1/2) -- the next step, where we do Division
5 + 36 - 0.5 --- the result from that step
(5 + 36) - 0.5 --- Now we do the addition.
41 - 0.5 ---- which gives us this result
(41 - 0.5) --- Finally do your subtraction
40.5
Looks like the answer is correct!!
And, if you want to know the extended ruleset that we use for order of operations, then look below.
QB64's order of operations (as ripped from my math evaluator):
'Exponents with PL 20
i = i + 1: OName(i) = "^": PL(i) = 20
i = i + 1: OName(i) = "SQR": PL(i) = 20
i = i + 1: OName(i) = "ROOT": PL(i) = 20
'Multiplication and Division PL 30
i = i + 1: OName(i) = "*": PL(i) = 30
i = i + 1: OName(i) = "/": PL(i) = 30
'Integer Division PL 40
i = i + 1: OName(i) = "\": PL(i) = 40
'MOD PL 50
i = i + 1: OName(i) = "MOD": PL(i) = 50
'Addition and Subtraction PL 60
i = i + 1: OName(i) = "+": PL(i) = 60
i = i + 1: OName(i) = "-": PL(i) = 60
'Relational Operators =, >, <, <>, <=, >= PL 70
i = i + 1: OName(i) = "<>": PL(i) = 70 'These next three are just reversed symbols as an attempt to help process a common typo
i = i + 1: OName(i) = "><": PL(i) = 70
i = i + 1: OName(i) = "<=": PL(i) = 70
i = i + 1: OName(i) = ">=": PL(i) = 70
i = i + 1: OName(i) = "=<": PL(i) = 70 'I personally can never keep these things straight. Is it < = or = <...
i = i + 1: OName(i) = "=>": PL(i) = 70 'Who knows, check both!
i = i + 1: OName(i) = ">": PL(i) = 70
i = i + 1: OName(i) = "<": PL(i) = 70
i = i + 1: OName(i) = "=": PL(i) = 70
'Logical Operations PL 80+
i = i + 1: OName(i) = "NOT": PL(i) = 80
i = i + 1: OName(i) = "AND": PL(i) = 90
i = i + 1: OName(i) = "OR": PL(i) = 100
i = i + 1: OName(i) = "XOR": PL(i) = 110
i = i + 1: OName(i) = "EQV": PL(i) = 120
i = i + 1: OName(i) = "IMP": PL(i) = 130
i = i + 1: OName(i) = ",": PL(i) = 1000
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
12-13-2023, 03:59 AM
(This post was last modified: 12-13-2023, 08:51 AM by PhilOfPerth.)
Thanks Steve.
You're right, I had it all wrong!
Not sure why, but it seems we can't just re-phrase the whole expression, but just complete each operation step-by-step.
Sorry for the trivia, it just didn't "add up" for me!
I'll go away and play some more.