Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cstring>
- #include <conio.h>
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- int main(void)
- {
- bool koniec = false;
- bool war1 = false;
- bool war2 = false;
- do
- {
- char pesel[11];
- do
- {
- *(pesel + 11) = 0;
- printf("podaj nr PESEL\n");
- scanf("%s", pesel);
- printf("\n");
- if(strlen(pesel) > 11)
- {
- printf("blad\n");
- printf("ciag jest za dlugi\n");
- printf("\n_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n\n");
- }
- if(strlen(pesel) < 11)
- {
- printf("blad\n");
- printf("ciag jest za krotki\n");
- printf("\n_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n\n");
- }
- }
- while(strlen(pesel) != 11 );
- char plec;
- while(1)
- {
- printf("podaj oznaczenie plci K->kobieta M->mezczyzna\n");
- // scanf("%c",&plec); //z nieznanego mi powodu podczas uzywania funkcji scanf, pierwsza petla omija ten wiersz i przechodzi dalej
- cin >> plec; //dlatego skorzystalem z biblioteki iostream
- printf("\n");
- if(plec == 'K' || plec == 'M')
- break;
- }
- if(plec == 'K')
- {
- if((((int)pesel[9]) - '0') % 2 == 0)
- war1 = true;
- }
- else
- {
- if((((int)pesel[9]) - '0') % 2 != 0)
- war1 = true;
- }
- // printf("\n_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n\n");
- // printf("\npesel ma odpowiednia dlugosc\n");
- // printf("%s\n", pesel);
- int wagi[] = {1, 3, 7, 9, 1, 3, 7, 9, 1, 3};
- int wyniki[10];
- for (int i = 0; i < 10; i++)
- {
- wyniki[i] = (((int)pesel[i]) - '0') * wagi[i];
- }
- int suma = 0;
- for (int i = 0; i < 10; i++)
- {
- // printf("%d, ", wyniki[i]);
- wyniki[i] = wyniki[i] % 10;
- // printf("%d\n", wyniki[i]);
- suma += wyniki[i];
- }
- // printf("suma %d\n", suma);
- suma = suma % 10;
- // printf("suma %d\n", suma);
- // printf("pesel[10] %d\n", ((int)pesel[10]) - '0');
- suma = 10 - suma;
- suma = suma % 10;
- // printf("suma %d\n", suma);
- if (suma == (((int)pesel[10]) - '0'))
- war2 = true;
- if (war1 && war2)
- {
- printf("podany ciag jest poprawnym numerem pesel\n");
- koniec = true;
- }
- else
- {
- printf("podany ciag nie jest poprawnym numerem pesel\n\n");
- printf("_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n\n");
- getch();
- system( "cls" );
- }
- }
- while(koniec != true);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement