Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. typedef enum {
  6.     ONE_BED, TWO_BEDS, SUPERIOR, DELUXE, SUITE
  7. } roomtype;
  8.  
  9. typedef struct {
  10.     int number;
  11.     roomtype type;
  12.     int occupied;
  13.     double price;
  14. } room;
  15.  
  16. typedef struct {
  17.     char name[50];
  18.     char address[50];
  19.     int num_rooms;
  20.     room rooms[100];
  21. } hotel;
  22.  
  23. int main() {
  24.     hotel hotels[3];
  25.     int i;
  26.     for(i = 0; i < 3; i++) {
  27.         printf("Vnesete ime i adresa na hotelot %d:\n", i + 1);
  28.         gets(hotels[i].name);
  29.         gets(hotels[i].address);
  30.         printf("Vnesete broj na sobi vo hotelot %d:\n", i + 1);
  31.         scanf("%d", &hotels[i].num_rooms);
  32.         int j;
  33.         printf("Vnesete podatoci za sekoja od sobite na hotelot %d:\n", i + 1);
  34.         for(j = 0; j < hotels[i].num_rooms; j++) {
  35.             printf("Vnesete podatoci za soba %d:\n", j + 1);
  36.             int type;
  37.             scanf("%d %d %d %lf",
  38.                     &hotels[i].rooms[j].number,
  39.                     &type,
  40.                     &hotels[i].rooms[j].occupied,
  41.                     &hotels[i].rooms[j].price);
  42.             getchar();
  43.             hotels[i].rooms[j].type = (roomtype) type;
  44.         }
  45.     }
  46.     char hotel_to_search[50];
  47.     roomtype type_to_search;
  48.     gets(hotel_to_search);
  49.     int type;
  50.     scanf("%d", &type);
  51.     type_to_search = (roomtype) type;
  52.     for(i = 0; i < 3; i++) {
  53.         if(!strcmp(hotels[i].name, hotel_to_search)) {
  54.             int j;
  55.             for(j = 0; j < hotels[i].num_rooms; j++) {
  56.                 if(hotels[i].rooms[j].type == type_to_search && !hotels[i].rooms[j].occupied) {
  57.                     printf("Sobata so broj %d e slobodna\n", hotels[i].rooms[j].number);
  58.                 }
  59.             }
  60.         }
  61.     }
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement