Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cstring>
  3. #include <conio.h>
  4. #include <cstdlib>
  5. #include <iostream>
  6. using namespace std;
  7.  
  8.  
  9. int main(void)
  10. {
  11.     bool koniec = false;
  12.     bool war1 = false;
  13.     bool war2 = false;
  14.     do
  15.     {
  16.         char pesel[11];
  17.         do
  18.         {
  19.             *(pesel + 11) = 0;
  20.             printf("podaj nr PESEL\n");
  21.             scanf("%s", pesel);
  22.             printf("\n");
  23.             if(strlen(pesel) > 11)
  24.             {
  25.                 printf("blad\n");
  26.                 printf("ciag jest za dlugi\n");
  27.                 printf("\n_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n\n");
  28.             }
  29.             if(strlen(pesel) < 11)
  30.             {
  31.                 printf("blad\n");
  32.                 printf("ciag jest za krotki\n");
  33.                 printf("\n_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n\n");
  34.             }
  35.         }
  36.         while(strlen(pesel) != 11 );
  37.  
  38.         char plec;
  39.         while(1)
  40.         {
  41.             printf("podaj oznaczenie plci K->kobieta M->mezczyzna\n");
  42.             //  scanf("%c",&plec); //z nieznanego mi powodu podczas uzywania funkcji scanf, pierwsza petla omija ten wiersz i przechodzi dalej
  43.             cin >> plec;            //dlatego skorzystalem z biblioteki iostream
  44.             printf("\n");
  45.             if(plec == 'K' || plec == 'M')
  46.                 break;
  47.         }
  48.         if(plec == 'K')
  49.         {
  50.             if((((int)pesel[9]) - '0') % 2 == 0)
  51.                 war1 = true;
  52.         }
  53.         else
  54.         {
  55.             if((((int)pesel[9]) - '0') % 2 != 0)
  56.                 war1 = true;
  57.         }
  58. //      printf("\n_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n\n");
  59. //      printf("\npesel ma odpowiednia dlugosc\n");
  60. //      printf("%s\n", pesel);
  61.  
  62.  
  63.         int wagi[] = {1, 3, 7, 9, 1, 3, 7, 9, 1, 3};
  64.         int wyniki[10];
  65.         for (int i = 0; i < 10; i++)
  66.         {
  67.             wyniki[i] = (((int)pesel[i]) - '0') * wagi[i];
  68.         }
  69.         int suma = 0;
  70.         for (int i = 0; i < 10; i++)
  71.         {
  72. //          printf("%d, ", wyniki[i]);
  73.             wyniki[i] = wyniki[i] % 10;
  74. //          printf("%d\n", wyniki[i]);
  75.             suma += wyniki[i];
  76.         }
  77. //      printf("suma %d\n", suma);
  78.         suma = suma % 10;
  79. //      printf("suma %d\n", suma);
  80. //      printf("pesel[10] %d\n", ((int)pesel[10]) - '0');
  81.         suma = 10 - suma;
  82.         suma = suma % 10;
  83. //      printf("suma %d\n", suma);
  84.  
  85.         if (suma == (((int)pesel[10]) - '0'))
  86.             war2 = true;
  87.  
  88.  
  89.         if (war1 && war2)
  90.         {
  91.             printf("podany ciag jest poprawnym numerem pesel\n");
  92.             koniec = true;
  93.         }
  94.         else
  95.         {
  96.             printf("podany ciag nie jest poprawnym numerem pesel\n\n");
  97.             printf("_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n\n");
  98.             getch();
  99.             system( "cls" );
  100.         }
  101.     }
  102.     while(koniec != true);
  103.     getch();
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement