Credit Card Validator in C++
A Credit Card Validator(CCV) is a software that verifies your credit card and validates it, this program is written using C++ language. CCV helps to verify the card is a valid credit card or not.
This program is based on a simple logic that we will discuss in detail. This program uses the Luhn Algorigthm to validate a Credit Card number.
Features
- Validate your Credit Card
- Completely Secure
- Works Offline
- No Internet Required
- Faster
- Time Saving
- Reliable
Approach
Credit Card Number Validator, the last digit of a credit card number is the check digit, which protects against transcription errors such as an error in a single digit or switching two digits. The following method is used to verify actual credit card numbers but, for simplicity, we will describe it for numbers with 8 digits instead of 16:
- Starting from the rightmost digit, form the sum of every alternate digit. For example, if the credit card number is 43589795, then you form the sum: 5 + 7 + 8 + 3 = 23 .
- Double each of the digits that were not included in the step 1 . Add all digits of the resulting numbers. For example, with the number given above, digits left out in step 1 from rightmost : 9 , 9 , 5 and 4 , doubling the digits, yields: 18 18 10 8. Adding all digits in these values yields: 1 + 8 + 1 + 8 + 1 + 0 + 8 = 27 .
- Add the sums of the two preceding steps. If the last digit of the result is 0, or the sum is the multiple of 10 , then the credit card number is valid, else not valid. In our case, 23 + 27 = 50 , so the number is VALID.
System Requirements
- Processor - Intel Core Pentium or above
- Operating System - Windows vista or above
- Memory - 1Gb Ram or more
- Hard Disk Space - 5MB
Output
![]() |
Complete example code for Credit Carr Validator
#include <stdio.h> using namespace std; bool isNumberString(const string& s) { int main() { cout << "This program uses the Luhn Algorigthm to validate a CC number." << endl; while (true) { cout << "Please Enter a Credit Card Number to Validate: "; if (ccNumber == "exit") else if (!isNumberString(ccNumber)) { int len = ccNumber.length(); // Step 1 is to double every second digit, starting from the right. If it for (int i = len - 2; i >= 0; i = i - 2) { // Step 2 is to add every odd placed digit from the right to the value for (int i = len - 1; i >= 0; i = i - 2) { // Step 3 is to check if the final 'doubleEvenSum' is a multiple of 10. cout << (doubleEvenSum % 10 == 0 ? "VALID !" : "INVALID !") << endl; continue; return 0;
|