It works fine for the first few iterations, but afterwards it starts changing the final digit into a number that I know is not correct. Here is the code:
long long isbnToArray(long long userNum)
{
int i;
char isbnArray[20];
for (i = 0; i <12; i++)
{
long long userNumFirst;
long long userNumRem;
int j = 11 - i; // gives us the power of 10 required for the divisor/ modulus operators
long long int divR = pow(10.0, j);
userNumFirst = userNum / divR; // value of the first digit
userNumRem = userNum % divR; // remainder after division
isbnArray[i] = userNumFirst; // inputs the first ISBN digit value into the array
// printf("%d.", isbnArray[i]);
userNum = userNumRem; // sets the isbn number as the remainder for the next iteration of the loop, eg 123451234512 becomes 23451234512.
printf("userNum = %lli\n", userNum);
}
}
After the 2nd iteration, the final digit turns to '5' when it should remain a '2', and then it spirals after that. I cant figure out why.
When run, the values are:
userNum = 23451234512 (Expected)
userNum = 3451234512 (Expected)
userNum = 451234515 (Expected 451234512)
userNum = 51234519 (Expected 51234512)
userNum = 1234524 (Expected 1234512)
userNum = 234524 (Expected 234512)
userNum = 34524 (Expected 34512)
userNum = 4527 (Expected 4512)
userNum = 527 (Expected 512)
userNum = 32 (Expected 12)
userNum = 2 (Expected 2)
userNum = 0 (Expected 0)