Yeah, I knew I would screw it up somehow. Most of it I thought I was just taking your code and formatting it to fit mine, but I guess I didn't do that very well.
This part I thought I was taking your code correctly, but I guess not. I think I see how I messed it up anyway.
For line 37, that's what your code says (I think) except you're subtracting it instead. I was playing around with it to see what would differ since I don't know exactly what you're doing with that. I'm also afraid that I don't know much about chars and strings so I don't know what you mean by what I have to do to '5' to get the integer 5.
For 44-61, I need to double every other number going from right to left. I'm storing them in separate arrays because if it is odd I'm doubling the number, and if the result is two digits, I need to add the digits separately (i.e. 14 -> 1 + 4) to work with Luhn's Algorithm.
I know 63 is insane, but it wasn't a very well thought out idea. It was simply to see what the output is and it worked well enough so I didn't clean it up. I would of course take that out in the final result.
Wolfgang: Ah, thank you. I didn't know that about For =)
Thank you two for your help. My class is 6 PM EST which is when this is due and I hope I can get it working by then.
Regards,
John
EDIT: After changing the array to 17, taking out the first loop in the input part, and changing the ++ to -- I have the input working now thanks to you. I checked the output and it matches what I got when I did Luhn's Algorithm manually. My only problem now is that I get "TotalSum equals 101450810"... so I'm not adding it correctly. I'm still using the same code to add it:
1 2 3 4 5
|
while (d < 17)
{
TotalSum += NewestDigits[d];
d++;
}
|
I checked the output for NewestDigits and it's correct, so the problem lies within this part.
EDIT X2: I have it working except after testing some, it's not taking the last integer of Digits and putting it into NewDigits and NewDigitsRemainder. Instead, it seems to be putting in a static -4 and -8 in them respectively even if I cut the size of the arrays down so they wouldn't fit.
FINAL EDIT: I got it working finally. I took the solution from here:
http://www.daniweb.com/forums/thread28270.html
I took the code given there, reformatted it, and replaced your code with:
1 2 3 4 5
|
for (int b = 0; b < 16; b++)
{
char Temp = DigitsChar[b];
Digits[b] = atoi(&Temp);
}
|
It may not be the best solution, as stated in the thread, but I'm not concerned about the safety of my code as it's for a class. It works, so I'm good. Thank you two for your help.