Advertisement
Kostiggig

LAB_15 -> 1

Dec 3rd, 2022
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <stdbool.h>
  5. #include <locale.h>
  6. #include <string.h>
  7. #include <time.h>
  8.  
  9. struct Citizen {
  10.     char name[100];
  11.     int age;
  12.     char gender[1];
  13. };
  14.  
  15. void task_1() {
  16.     int mutableCountOfCitizens = 0, womenCount = 0, menCount = 0;
  17.     printf("Enter the count of the citizens: ");
  18.     scanf("%d", &mutableCountOfCitizens);
  19.  
  20.     if(mutableCountOfCitizens < 0) {
  21.         printf("The count of the citizens cannot be negative");
  22.     } else {
  23.         const int immutableCountOfCitizens = mutableCountOfCitizens;
  24.         struct Citizen citizens[mutableCountOfCitizens];
  25.         int currentCitizenIndex = 0;
  26.         while(mutableCountOfCitizens != 0) {
  27.             char name[100];
  28.             int age;
  29.             char gender[1];
  30.  
  31.             printf("\nEnter name: ");
  32.             scanf("%s", citizens[currentCitizenIndex].name);
  33.  
  34.             printf("Enter age: ");
  35.             scanf("%d", &citizens[currentCitizenIndex].age);
  36.  
  37.             printf("Enter gender F - woman, M - men: ");
  38.             scanf("%s", citizens[currentCitizenIndex].gender);
  39.  
  40.             bool isNotMan = strcmp(citizens[currentCitizenIndex].gender, "M") != 0;
  41.             bool isNotWoman = strcmp(citizens[currentCitizenIndex].gender, "F") != 0;
  42.            
  43.             if(citizens[currentCitizenIndex].age < 0 || (isNotMan && isNotWoman)) {
  44.                 printf("Check out correctnesses of the data");
  45.                 printf("\nName: %s, age: %d, gender: %s", citizens[currentCitizenIndex].name, citizens[currentCitizenIndex].age, citizens[currentCitizenIndex].gender);
  46.             } else {
  47.                 if(isNotMan) womenCount++; else menCount++;
  48.                 currentCitizenIndex++;
  49.                 mutableCountOfCitizens--;
  50.             }
  51.         }
  52.  
  53.         for(int i = 0; i < immutableCountOfCitizens; i++) {
  54.             printf("\n");
  55.             struct Citizen citizen = citizens[i];
  56.             printf("{ name: %s, age: %d,  gender: %s }", citizen.name, citizen.age, citizen.gender);
  57.         }
  58.  
  59.         printf("\n\nCount of the women - %d, count of the men - %d", womenCount, menCount);
  60.         printf("\n\n");
  61.         if(womenCount > menCount) {
  62.             printf("Count of the men exceeds women for %d", womenCount - menCount);
  63.         } else {
  64.             if (womenCount == menCount)
  65.             {
  66.                 printf("Count of the women and the men are the same");
  67.             } else {
  68.                 printf("Count of the men exceeds women for %d", menCount - womenCount);
  69.             }
  70.            
  71.         }
  72.  
  73.     }
  74. }
  75.  
  76. int main() {
  77.    
  78.    
  79.     int numOfTask = 0;
  80.     printf("%d", 'c' == 'c');
  81.     do
  82.     {
  83.         printf("\nEnter a number of the task: ");
  84.         scanf("%d", &numOfTask);
  85.  
  86.         switch (numOfTask) {
  87.         case 1:
  88.             task_1();
  89.             break;
  90.         default:
  91.             printf("\nThe task by num %d has not found", numOfTask);
  92.             break;
  93.         }
  94.  
  95.     } while (numOfTask != 0);
  96.  
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement