Coders Packet

Credit Card validator in C++

By Aditi Chauhan

It is a simple project in c++ using Luhn's Algorithm to validate a user credit card number. This program works for all types of cards like Visa, Amex, Master cards, etc.

A Credit Card allows you to validate that the given value could be a valid credit card number or not using Luhn's Algorithm.

Using Luhn's Algorithm, we take each digit of the credit card number and double every second digit number from right to left. If double of these digits produces a sum greater than nine, subtract nine from the sum to get a single-digit like that (ex: 14=1+4,18=1+8).

We take the sum of all single digits from right to left like (ex: 5+4+1+3+1+4+6+8= 32) and also add all digits in the odd places in the card number, If the sum of results of these digits is divisible by 10, then the card number is valid; otherwise; it is invalid.

The program first determines the type of card and then validates it and checks the given credit card number is valid or not.

Download Complete Code


No comments yet