Jump to content
Sign in to follow this  
onestcoder

Math Help

Recommended Posts

onestcoder

$x = 1.87 * 1.5 * 73 + 9.40 * 1.5 * 24 + 4.03 * 3 / 100

This should equal 5.55255 BUT it returns 543.2859


Need a website: http://www.iconixmarketing.com

Share this post


Link to post
Share on other sites
onestcoder

OK it doent like the string. Works like this:

$x = 1.87 * 1.5 * 73
$x2 = 9.40 * 1.5 * 24
$x3 = 4.03 * 3
$x4 = $x + $x2 + $x3
$x5 = $x4 / 100

MsgBox(-1, $x5, $x5)

Is there a way to write this on 1 line?


Need a website: http://www.iconixmarketing.com

Share this post


Link to post
Share on other sites
Yashied

OK it doent like the string. Works like this:

$x = 1.87 * 1.5 * 73
$x2 = 9.40 * 1.5 * 24
$x3 = 4.03 * 3
$x4 = $x + $x2 + $x3
$x5 = $x4 / 100

MsgBox(-1, $x5, $x5)

Is there a way to write this on 1 line?

$x = (1.87 * 1.5 * 73 + 9.40 * 1.5 * 24 + 4.03 * 3) / 100

Share this post


Link to post
Share on other sites
oMBRa

$x = (1.87 * 1.5 * 73 + 9.40 * 1.5 * 24 + 4.03 * 3) / 100

you've beaten me on time ^_^

@OP

$x = 1.87 * 1.5 * 73 + 9.40 * 1.5 * 24 + 4.03 * 3 / 100 = 543.2859

Share this post


Link to post
Share on other sites
Melba23

onestcoder,

Your maths syntax is very anbiguous. You should always clearly show, by the use of parentheses, the order in which the operators are to be applied - if not the compiler uses its own priority listing. From the Help File:

When more than one operator is used in an expression the order in which things happen is controlled by operator precedence.  The precedence used in AutoIt is given below.  Where two operators have the same precedence the expression is evaluated left to right.

From highest precedence to lowest:

    NOT
    ^
    * /
    + -
    &
    < > <= >= = <> ==
    AND OR 

e.g. 2 + 4 * 10 is evaluated as 42:

    4 * 10  (equals 40)

    2 + 40  (equals 42)

As the * has a higher precedence than + it occurs before the addition.

So your line should read:

$x = ((1.87 * 1.5 * 73) + (9.40 * 1.5 * 24) + (4.03 * 3)) / 100

and then you get the "correct" answer!

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
CodyBarrett

but what about bedmas? it shouldn't need the brackets... should it

Share this post


Link to post
Share on other sites
Yashied

$x = ((1.87 * 1.5 * 73) + (9.40 * 1.5 * 24) + (4.03 * 3)) / 100

((1.87 * 1.5 * 73) + (9.40 * 1.5 * 24) + (4.03 * 3)) / 100 = (1.87 * 1.5 * 73 + 9.40 * 1.5 * 24 + 4.03 * 3) / 100

Multiplication (division) ALWAYS has preoritet over addition (subtraction). This is mathematics (Grade ~3). There's no need to read the help file.

^_^

Share this post


Link to post
Share on other sites
Melba23

Yashied,

My mathematics teachers of long, long ago taught me to use parentheses to avoid any possible confusion.

The OP was confused - using parentheses removes the confusion.

I just used more of them than you did!

CodyBarrett,

I have never come across "bedmas" before - I will try to remember it.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Yashied
onestcoder

Thank you very much (Yashied, Melba23, CodyBarrett, oMBRa) ^_^


Need a website: http://www.iconixmarketing.com

Share this post


Link to post
Share on other sites
tarquinn

Yashied,

My mathematics teachers of long, long ago taught me to use parentheses to avoid any possible confusion.

The OP was confused - using parentheses removes the confusion.

I just used more of them than you did!

CodyBarrett,

I have never come across "bedmas" before - I will try to remember it.

M23

I've never heard of bedmas, what's the B? Brackets?

I've always been taught PEMDAS. Parenthesis, etc..

Share this post


Link to post
Share on other sites
CodyBarrett

its Gr3 math in canada

B rackets

E xponents

D ivision

M ultiplication

A dding

S ubtracting

... not sure if it applies to programming though.. but up there it does

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×