Hi all,
I am trying to use BigNumber in my game but am getting stuck. To try and wrok out where I am going wrong I’ve got some really basic test code that doesn’t seem to do what I expect? I am trying to find the average of lst=[1,2,3,4,5,6,7,8] which I would expect to be 4.5 but my code returns 4?
I am including #include <bignum.h> so I guess I’m doing something silly but can’t see what it is? Thanks for any advice.
tst
Sum is 36 Count is 8 Average is 4
VerbRule(tst)
'tst'
: tstAction
verbPhrase = 'tst'
;
DefineIAction(tst)
execAction()
{
local lst=[1,2,3,4,5,6,7,8];
local sum=0;
local cnt=0;
local avg = new BigNumber(0 , 2);
foreach(local cur in lst)
{
cnt++;
sum=sum+cur;
}
avg=(sum/cnt);
"Sum is <<sum>> Count is <<cnt>> Average is <<avg>> ";
}
;