I’m trying to write a function called checkCreditCard which could be used in a website for an online store. I’m trying to make the function so it will check whether the credit card number typed in by a user is valid. I need to write a function that has one parameter: an account number (int) that will check whether the account number is valid and will display a trace statement that gives the result (e.g. credit card number 51312 is not valid)
I know I need to use the division operator and mod operator (/ and %) to strip off each digit so that the first 4 digits can be added to find the sum and then use the mod operator (%) along with an if-else statement to determine whether the remainder of the sum divided by 9 is equal to the last digit, so that the number is valid.
I’ve gotten some help for how to set it up, but am still confused at how to finish this.
function checkCreditCard ( acctNumber: int )
{ var num: int = acctNumber;
var d1: int = num / 10000; // d1 will now be the first (leftmost) digit
num = num % 10000; // num will now be the four rightmost digits
Any help would be greatly appreciated!