Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. struct Garage {
  5.   int number_car;
  6.   int probeg;
  7.   char date_remont[8];
  8.   char color[15];
  9.   char mark[10];
  10. };
  11.  
  12. int main()
  13. {
  14.   int size_garage = 1;
  15.   struct Garage ourGarage[] = {
  16.     1, 100, "31.31.18", "green", "bmw",
  17.     2, 150, "15.31.18", "green", "bmw"
  18.   };
  19.  
  20.   int command;
  21.   while (1>0) {
  22.     printf("Choose command:\n1.All cars which have colour green\n2.Car with the lastes date of repair:\n");
  23.     scanf("%d", &command);
  24.  
  25.     if (command == 1) {
  26.       for (int i = 0; i < size_garage; i++) {
  27.         struct Garage tmpGarage = ourGarage[i];
  28.  
  29.         if (!strcmp(tmpGarage.color, "green")) {
  30.           printf("Brand car is: %s, its number is %d\n", tmpGarage.mark, tmpGarage.number_car);
  31.          
  32.         }
  33.       }
  34.     } else if ( command == 2) {
  35.       int numberID = ourGarage[0].number_car;
  36.       int day, month, year;
  37.  
  38.        sscanf(ourGarage[0].date_remont, "%d.%d.%d",&day,&month,&year);
  39.      
  40.       for (int i = 1; i < size_garage; i++) {
  41.         int tday, tmonth, tyear;
  42.         sscanf(ourGarage[i].date_remont, "%d.%d.%d",&tday,&tmonth,&tyear);
  43.         if (tyear > year){
  44.           day = tday;
  45.           month = tmonth;
  46.           year = tyear;
  47.           numberID = ourGarage[i].number_car;
  48.         } else if ((tyear == year) && (tmonth > month)) {
  49.           day = tday;
  50.           month = tmonth;
  51.           year = tyear;
  52.           numberID = ourGarage[i].number_car;
  53.         } else if ((tyear == year) && (tmonth == month) && (tday > day) ) {
  54.           day = tday;
  55.           month = tmonth;
  56.           year = tyear;
  57.           numberID = ourGarage[i].number_car;
  58.         }
  59.       }
  60.       printf("Number car wich have the latest date of repair: %d \n", numberID);
  61.     }
  62.   }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement