|
// checksum2.cpp
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <assert.h>
#include "convert.h"
int main(int argc, char* argv[])
{
_tstring route = _T("12345678");
_tcout << _T("routing number: ") << route << endl;
int i = 0, c = 0;
for( _tstring::const_iterator it = route.begin();
it != route.end(); i++, it++ )
{
switch( i % 3 + 1 )
{
case 1:
c += 7 * CharToNumber( *it );
break;
case 2:
c += 3 * CharToNumber( *it );
break;
case 3:
c += 9 * CharToNumber( *it );
break;
default:
assert( false );
break;
}
c %= 10;
}
_tcout << _T("check digit: ") << c << endl;
_tcout << _T("routing number with check digit: ") << route << 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.