A tiny, fast C++ console app that validates credit card numbers using the Luhn algorithm.
Type a card number, get VALID / INVALID with basic stats. No dependencies.
- β Luhn algorithm validation
- π’ Digits-only and length checks (13β19)
- π§Ή Simple, robust I/O handling
- π» Works on macOS/Linux/Windows (console)
- C++17 or later
- A C++ compiler (e.g.,
g++,clang++, or MSVC) - Terminal/Console
g++ -std=c++17 -O2 -Wall -Wextra -o credit-card-validator src/main.cpp
./credit-card-validatorg++ -std=c++17 -O2 -Wall -Wextra -o credit-card-validator.exe src/main.cpp
credit-card-validator.exemkdir build && cd build
cmake ..
cmake --build .
# Run
./credit-card-validator # macOS / Linux
credit-card-validator.exe # WindowsCard Number: 4539578763621486 Length: 16 digits Status: β VALID
1. Traverse the number from right to left.
2. Double every second digit; if result > 9, subtract 9.
3. Sum all digits.
4. If sum % 10 == 0 β VALID, else INVALID.