Here is the assignment for a function that will be part of my program that I can't figure out how to start even: (its for a program that validates credit card numbers)
Function that checks if the last digit is correct, use the following algorithm:
-In each of the chars with an EVEN index (indices 0,2,4,6, etc)
-get the int value represented by the char (for example 7
from '7') // our teacher mentioned in class that we can do
this by doing something like '2' - '0' but I have no idea how to
put this into a code.
-double it (for example 7*2, which is 14)
-if doubling it has 2 digits, add those digits (ex 1+4, which
is 5) otherwise, just use the doubled value (if it has one
digit) // I'm super confused...
-add that to a sum. //what sum?
-Add the values of each of the chars (converted to the int it represents) n the ODD index positions to the sum. //again, confused
-If a sum is a multiple of 10 (use % operator), its correct (return in a return statement 1) otherwise, its incorrect (return 0)
-I don't want or need anybody to simply hand me the solution, but PLEASE help me out. This seems like the hardest function to do in our program assignment and I can't figure out how to code it.
This is all I have started for this particular code:
Code:
char lastChar;
if(lastChar == '0' || lastChar == '2' || lastChar == '4' || lastChar == '6' || lastChar == '8')
-Pathetic, I know. But I'm desperate to finally finish this. Please help me out any way you can!