Advertisement
Donald_Fortier

int getIsbnChecksum( string );// C++

May 28th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. using namespace std;
  2.  
  3. int getIsbnChecksum( string );// Prototype for this function.
  4.  
  5. int getIsbnChecksum( string isbnBase ) {
  6.     int sum = 0;
  7.     for ( int i = 0; i < 12; i++ ) {
  8.         if ( i % 3 != 0 )
  9.             sum += int( isbnBase[ i ] - '0' );
  10.         else
  11.             sum += int( isbnBase[ i ] - '0' ) * 3;
  12.     }
  13.     int checksum = ( 10 - sum % 10 ) % 10;
  14.  
  15.     return checksum;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement