Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- struct Garage {
- int number_car;
- int probeg;
- char date_remont[8];
- char color[15];
- char mark[10];
- };
- int main()
- {
- int size_garage = 1;
- struct Garage ourGarage[] = {
- 1, 100, "31.31.18", "green", "bmw",
- 2, 150, "15.31.18", "green", "bmw"
- };
- int command;
- while (1>0) {
- printf("Choose command:\n1.All cars which have colour green\n2.Car with the lastes date of repair:\n");
- scanf("%d", &command);
- if (command == 1) {
- for (int i = 0; i < size_garage; i++) {
- struct Garage tmpGarage = ourGarage[i];
- if (!strcmp(tmpGarage.color, "green")) {
- printf("Brand car is: %s, its number is %d\n", tmpGarage.mark, tmpGarage.number_car);
- }
- }
- } else if ( command == 2) {
- int numberID = ourGarage[0].number_car;
- int day, month, year;
- sscanf(ourGarage[0].date_remont, "%d.%d.%d",&day,&month,&year);
- for (int i = 1; i < size_garage; i++) {
- int tday, tmonth, tyear;
- sscanf(ourGarage[i].date_remont, "%d.%d.%d",&tday,&tmonth,&tyear);
- if (tyear > year){
- day = tday;
- month = tmonth;
- year = tyear;
- numberID = ourGarage[i].number_car;
- } else if ((tyear == year) && (tmonth > month)) {
- day = tday;
- month = tmonth;
- year = tyear;
- numberID = ourGarage[i].number_car;
- } else if ((tyear == year) && (tmonth == month) && (tday > day) ) {
- day = tday;
- month = tmonth;
- year = tyear;
- numberID = ourGarage[i].number_car;
- }
- }
- printf("Number car wich have the latest date of repair: %d \n", numberID);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement