|
// checksum6.cpp
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <assert.h>
#include "convert.h"
int main(int argc, char* argv[])
{
// _tstring number = _T("0823"); // c = 5
_tstring number = _T("276616973212561"); // c = 5
_tcout << _T("number: ") << number << endl;
unsigned int c = 10;
for( _tstring::iterator it = number.begin();
it != number.end(); it++ )
{
// Consume non digits
while( it != number.end() && false == isdigit( *it ) ) { it++; }
if( it == number.end() ) { break; }
c += CharToNumber( *it );
if( c > 10 ) { c -= 10; }
c *= 2;
if( c >= 11 ) { c -= 11; }
}
c = 11 - c;
if( 10 == c ) { c = 0; }
_tcout << _T("check digit is: ") << c << endl;
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.