Does anybody know the codes for this problem? or does anybody encountered this type of problem?
(Check Digit. Credit cards usually have a so-called check digit. This is a single digit that is assigned when
the account number is developed and has a special property. One particularly simple mechanism is to
assign the last digit of the sum of all the other digits. For example, suppose we have a nine-digit account
number (including the check digit ). The check digit would be the sum of the eight digits. This digit could
be placed anywhere in the sequence, say the third digit. As a full example, suppose the eight numbers
are 12345678. Their sum is 36; thus, 6 is the check digit. The account number is therefore 126345678.
Write a program to read in a nine digit integer from the keyboard and check it for these rules. Write
“account number is okay” or “account number is not okay” for the results of the test.)
there are 2 ways to do this. you can get the input as a string and chop it up and convert the chunks into integers (or whatever else), or you can do it with math.
often one will read as strings to do basic error checking (did the user put in abcdef instead of 123456?) anyway, so that method has additional merits.
the math approach for a different digit:
(123/10) %10 = 12 %10 = 2.
the most and least significant digit in base 10 are easy, the middle ones require a little additional work. It takes a while to get used to tricks with % but once you do, its very useful.