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:
int i =3;
void combinePass (char k)
pass += (k - 48) * pow(10,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
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:
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:
I would really appreciate, if someone could explain why it is happening so.