Well, this is a class code. It is quite possible that result and i are data members.
Anyways, the error I see is, that valueAt is a constant function and you are trying to modify a variable in a read only function which is not permitted.
Yes, right, result and i are data members. I declared another varaibles inside the function, now it is working.
Thank you, guys, I learned something new today!!