Page 1 of 1
Need help in array calculation
Posted: Wed Apr 29, 2020 8:24 am
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
Re: Need help in array calculation
Posted: Wed Apr 29, 2020 9:19 am
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.
Re: Need help in array calculation
Posted: Wed Apr 29, 2020 11:07 am
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