That won't quite work, as '9' + 7 is not '6' as desired.
This, I think, will work.
try this:
Code:
int temp, int exp = 0, int encrypted = 0, int normal;
//set normal to the val to be encrypted.
while(normal > 0){
temp = normal % 10; // gets the last digit of normal
temp += 7; //adds 7
temp = temp % 10; //does wraparound such that 10 = 0, 11 = 1, etc.
encrypted += temp * pow(10,exp); // puts this digit in its appropriate place,
exp ++; //now, we want to do the next digit, so increase the exponent,
normal /= 10; //shift all the digits down, discarding the lowest which we've already encrypted.
}
Note, you can condense a lot of these steps(you can do it in 3 lines), but it's clearer written like this.