MeehoweCK

Untitled

Jan 12th, 2023
777
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     string pesel;
  8.     cout << "Wpisz pesel: ";
  9.     cin >> pesel;
  10.     if(pesel.size() != 11)
  11.     {
  12.         cout << "Pesel jest nieprawidlowy.\n";
  13.         return 0;
  14.     }
  15.  
  16.     for(short i = 0; i < 11; ++i)
  17.         if(pesel[i] < '0' || pesel[i] > '9')
  18.         {
  19.             cout << "Pesel jest nieprawidlowy.\n";
  20.             return 0;
  21.         }
  22.  
  23.     int suma = 0;
  24.     suma += (pesel[0] - 48);
  25.     suma += (pesel[1] - 48) * 3;
  26.     suma += (pesel[2] - 48) * 7;
  27.     suma += (pesel[3] - 48) * 9;
  28.     suma += (pesel[4] - 48);
  29.     suma += (pesel[5] - 48) * 3;
  30.     suma += (pesel[6] - 48) * 7;
  31.     suma += (pesel[7] - 48) * 9;
  32.     suma += (pesel[8] - 48);
  33.     suma += (pesel[9] - 48) * 3;
  34.     suma += (pesel[10] - 48);
  35.  
  36.     //cout << suma << endl;
  37.     if(suma % 10 == 0)
  38.         cout << "Pesel jest prawidlowy.\n";
  39.     else
  40.         cout << "Pesel jest nieprawidlowy.\n";
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment