Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <locale.h>
- #include <string.h>
- #include <time.h>
- struct Citizen {
- char name[100];
- int age;
- char gender[1];
- };
- void task_1() {
- int mutableCountOfCitizens = 0, womenCount = 0, menCount = 0;
- printf("Enter the count of the citizens: ");
- scanf("%d", &mutableCountOfCitizens);
- if(mutableCountOfCitizens < 0) {
- printf("The count of the citizens cannot be negative");
- } else {
- const int immutableCountOfCitizens = mutableCountOfCitizens;
- struct Citizen citizens[mutableCountOfCitizens];
- int currentCitizenIndex = 0;
- while(mutableCountOfCitizens != 0) {
- char name[100];
- int age;
- char gender[1];
- printf("\nEnter name: ");
- scanf("%s", citizens[currentCitizenIndex].name);
- printf("Enter age: ");
- scanf("%d", &citizens[currentCitizenIndex].age);
- printf("Enter gender F - woman, M - men: ");
- scanf("%s", citizens[currentCitizenIndex].gender);
- bool isNotMan = strcmp(citizens[currentCitizenIndex].gender, "M") != 0;
- bool isNotWoman = strcmp(citizens[currentCitizenIndex].gender, "F") != 0;
- if(citizens[currentCitizenIndex].age < 0 || (isNotMan && isNotWoman)) {
- printf("Check out correctnesses of the data");
- printf("\nName: %s, age: %d, gender: %s", citizens[currentCitizenIndex].name, citizens[currentCitizenIndex].age, citizens[currentCitizenIndex].gender);
- } else {
- if(isNotMan) womenCount++; else menCount++;
- currentCitizenIndex++;
- mutableCountOfCitizens--;
- }
- }
- for(int i = 0; i < immutableCountOfCitizens; i++) {
- printf("\n");
- struct Citizen citizen = citizens[i];
- printf("{ name: %s, age: %d, gender: %s }", citizen.name, citizen.age, citizen.gender);
- }
- printf("\n\nCount of the women - %d, count of the men - %d", womenCount, menCount);
- printf("\n\n");
- if(womenCount > menCount) {
- printf("Count of the men exceeds women for %d", womenCount - menCount);
- } else {
- if (womenCount == menCount)
- {
- printf("Count of the women and the men are the same");
- } else {
- printf("Count of the men exceeds women for %d", menCount - womenCount);
- }
- }
- }
- }
- int main() {
- int numOfTask = 0;
- printf("%d", 'c' == 'c');
- do
- {
- printf("\nEnter a number of the task: ");
- scanf("%d", &numOfTask);
- switch (numOfTask) {
- case 1:
- task_1();
- break;
- default:
- printf("\nThe task by num %d has not found", numOfTask);
- break;
- }
- } while (numOfTask != 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement