I was working on the hacker version of pset1 and I was using a for loop to grab the values of every single individual number (in CC#) and transfer it to an array. The for loop works fine, except that it absolutely butchers the final number. Ex: 378282246310005 is seen by the array as 37828224631000
The for loop in question does the following:
- It takes the CC# and divides it by 10CC#.length - loopCounter (initialized at 1) and places that value in an int (curVal).
- Does the same operation (CC# divided by 10CC#.length - loop counter) then minus the int curVal) and multiplies that entire value (incl. minus curVal) and multiplies it by 10CC#.length - loopCounter. It then places that value in a variable (long long) called num.
- It assigns the curVal to an array called numbers like so:
numbers [loopCounter] equals curVal.
Sorry if wording above is confusing. I guess I could clarify by PM'ing someone the actual code. Thanks for any help.
I've tried appending a value to the CC# so that the butchering only happens in a final, useless digit. That only lead to another problem (3782822463100050 becomes 3782822463100049)
I've "duct-taped" the issue by appending a 9 to the CC# that the user inputs (so that the second to last digit does not round down).