#Please help me, Code Doesnt follow MDAS rule

1 messages · Page 1 of 1 (latest)

tawdry sorrel
#

Idk what to do, i only have couple of hours left

queen houndBOT
#

Helper please have a look, thanks.

primal gazelle
#

what’s ur question tho

#

u just posted a bunch of pictures

tawdry sorrel
#

When i input 2+7x3÷5×0.5
It should be equal to 4.1
But instead it says 2.7
Idk what to correct in the code for it to do MDAS correctly, im a first year student

primal gazelle
#

have u tried checking if it follows the order of pemdas

tawdry sorrel
#

No the problem is that it goea from left to right calculation, it doesnt follow the mdas rule

#

It goes from 2+7 then x3 then ÷5 then x 0.5 which is wrong, idk what to do, ive searched for everything

fierce silo
#

can you post what you're typing in the console & what result you're getting exactly? it might help

tawdry sorrel
tawdry sorrel
#

Yes

devout coral
#

well, 1 strategy

#

do it MDAS

#

explicitly

#

so do one scan where you do the multiplication

#

another where you do division

#

another with addition

#

etc.

tawdry sorrel
#

Like seperately?

devout coral
#

yes

tawdry sorrel
#

But my teacher wants all at the same time

devout coral
#

from the perspective of the user it will all be at the same time

#

you just scan left to right

#

so

#

2 + 7 x 3 / 5 x 0.5

#

just do the division and multiplication left to right, leaving addition alone

#

2 + 21 / 5 x 0.5

#

2 + 4.25 x 0.5

#

2 + 2.0125

#

4.0125

#

just don't do addition or subtraction until you are done with multiplication and division

tawdry sorrel
#

Will my teacher accept it though

devout coral
#

i don't care