Unexplainable Coding Problem

Hey guys!
So, I have started working out with the Arduino after about a year and I was checking out the IR sensor and controlling it with a remote.
So, a part of the project would be to get a 4-digit password from the user, through the remote. The user presses a button on the remote and I and get the data for that button. Next, I convert that to the number that appears on the remote (I already decoded all the buttons). The number that the person entered at the beginning would go to the 4th place (from right) by multiply to 1000, the 2nd number entered goes to 3rd place by multiplying by 100 and adding to the previous thing and it goes on. Since the entered number is a char type, I subtract 48 to get the number. Here's the code for the part where the sort of assembly of the entered numbers to form the password happens:

long pass;
int i =3;
void combinePass (char k)
{
pass += (k - 48) * pow(10,i);
--i
}

According to me, this should work. But actually, the 4 digit number formed when, let's say, the user enters 1, 2, 3 and 4 is 1233. And it goes like
999
1199
1229
1233

However, when the --i statement is removed, I get 10000 as the number formed, which is again unexplainable, as i shouldn't have on impact on it. And it happens like:
1000
3000
6000
10000

Lastly, when the declaration of pass is changed from pass=0 to pass=1, things workout as planned. The number is 1234 and it happens like:
1000
1200
1230
1234

I would really appreciate, if someone could explain why it is happening so.

Hi and welcome.

Please, before anything else, read the forum manual (click !), and learn how to help helpers help you.

Your problem has already been explained some time ago (click !).

This one comes up about once a month.
Do not use pow for integer powers, just use multiplication or division

Also

 pass += (k - '0')

It looks like you are adding digits of a decimal number from left to right. If so this is far easier...

pass *=10;
pass += k - '0';

Or use the C function atoi().

As a further explanation of why what you tried didn’t work, pow uses floating point. FP has limited precision and introduces inaccuracies. Avoid FP, especially so on 8-bit CPUs with limited resources and no hardware acceleration.

Your problem is probably that the 'pow()' function uses floating-point and doesn't always result in the right value when truncated to an integer. pow(10,3); is probably coming out as 999.9... which truncates to 999, not 1000.