Need help in array calculation

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
kg300
Posts: 31
Joined: Thu May 31, 2018 6:25 am
Has thanked: 5 times
Been thanked: 1 time
Contact:

Need help in array calculation

Post by kg300 »

Put data in array through keypad then combine it in integier variable. When i press 1234 the result is same 1234. But when i put 12 the result is 1200 insted of 12. Please help to solve this problem
Attachments
Flowcode1.fcf
(13.5 KiB) Downloaded 163 times

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: Need help in array calculation

Post by Steve »

One way is to perform the final calculation differently depending on the value of Key_COUNT.

For example, when Key_COUNT is 4 then "Result = Key_ADD[0] * 1000 + Key_ADD[1] * 100 + Key_ADD[2] * 10 + Key_ADD[3]" is correct.

But for Key_COUNT = 2, "Result = Key_ADD[0] * 10 + Key_ADD[1]".

Another way would be to keep a running total of the result as the keys are entered. Each time a new on is entered, the existing result needs to shift one decimal place and the new key result becomes the lowest digit.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Need help in array calculation

Post by medelec35 »

Hi kg300, attached simplified flowchart might help.
The target device you are using will not have enough ram to compile either flowchart.
the * key is used to clear the result
Attachments
Flowcode1a.fcf
(13 KiB) Downloaded 157 times
Martin

Post Reply