Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. //  ##################################
  2. //  ##  ISBN                        ##
  3. //  ##  Uebung 3                    ## 
  4. //  ##  Beispiel 4                  ##
  5. //  ##  Etzlstorfer Simon           ##
  6. //  ##  Rev 1.0                     ##
  7. //  ##################################
  8.  
  9.  
  10. #include <iostream>
  11. #include <cmath>
  12. using namespace std;
  13. int main (){
  14.     int isbn[9];
  15.     int in = 0;
  16.     int i = 0;
  17.     int hoch = 8;
  18.     int x = 0;
  19.     int pruf = 0;
  20.     cout << "ISBN ohne Prüfziffer eingeben: ";
  21.     cin >> in;
  22.     cout << endl;
  23.     if (in < 100000000 || in > 999999999){
  24.         cout << "ISBN falsch" << endl;
  25.     }else{
  26.         while ( i <= 8 ){
  27.             isbn[i] = in / pow(10, hoch);
  28.             in = in - (isbn[i] * pow(10, hoch));
  29.             hoch --;
  30.             i ++;
  31.         }
  32.         i = 0;
  33.         while ( i <= 8){
  34.             x = x + (isbn[i]*(i+1));
  35.             i ++;
  36.         }
  37.         pruf = x%11;
  38.         i = 0;
  39.         cout << "ISBN: ";
  40.         while( i <= 8 ){
  41.             cout << isbn[i];
  42.             if (i == 0 || i == 3 ){
  43.                 cout << "-";
  44.             }
  45.             i ++;
  46.         }
  47.         if ( pruf < 10){
  48.             cout << "-" << pruf << endl;
  49.         }else{
  50.             cout << "-" << "X" << endl;
  51.         }
  52.     }
  53. }
  54.  
  55. /*
  56.  * Testfälle:
  57.  * ISBN ohne Prüfziffer eingeben: 344621367
  58.  *
  59.  * ISBN: 3-446-21367-8
  60.  * -------------------------------------------
  61.  * ISBN ohne Prüfziffer eingeben: 349913599
  62.  *
  63.  * ISBN: 3-499-13599-X
  64.  * -------------------------------------------
  65.  * ISBN ohne Prüfziffer eingeben: 123456789
  66.  *
  67.  * ISBN: 1-234-56789-X
  68.  * -------------------------------------------
  69.  * ISBN ohne Prüfziffer eingeben: 12345678
  70.  *
  71.  * ISBN falsch
  72.  * -------------------------------------------
  73.  * ISBN ohne Prüfziffer eingeben: 1234567891
  74.  *
  75.  * ISBN falsch
  76. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement