Verhoeff algorithm: Difference between revisions

m
Made code more C++ idiomatic.
m (Added language identifier.)
m (Made code more C++ idiomatic.)
Line 233:
<syntaxhighlight lang="c++">
 
#include <cstdint>
#include <iostream>
#include <string>
Line 266 ⟶ 267:
} };
 
int32_t verhoeff_checksum(std::string number, const bool doValidation, const bool doDisplay) {
if ( doDisplay ) {
std::string calculationType = doValidation ? "Validation" : "Check digit";
Line 302 ⟶ 303:
std::make_pair("123", true), std::make_pair("12345", true), std::make_pair("123456789012", false) };
 
for ( const data& test : tests ) {
int32_t digit = verhoeff_checksum(test.first, false, test.second);
std::cout << "The check digit for " << test.first << " is " << digit << "\n" << std::endl;
 
std::string numbers[2] = { test.first + std::to_string(digit), test.first + "9" };
for ( const std::string& number : numbers ) {
digit = verhoeff_checksum(number, true, test.second);
std::string result = ( digit == 1 ) ? "correct" : "incorrect";
897

edits