Advertisement
machkovskitomche

struct/enum

Jun 17th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<string.h>
  4. #define MAXPATNICI 5
  5. enum sostojba {stoi,dolu,gore};
  6.  
  7. typedef struct
  8. {
  9.     int sostojba;
  10.     int sprat;
  11.     int brpatnici;
  12. }lift;
  13.  
  14. typedef struct
  15. {
  16.     int sprat;
  17.     int kade;
  18. }patnik;
  19.  
  20.  
  21. void povikajlift(patnik *p,lift *l)
  22. {
  23.     if(p->sprat>l->sprat)
  24.     {
  25.         l->sostojba=1;
  26.         while(l->sprat<p->sprat)
  27.         {
  28.             (l->sprat)++;
  29.             printf("Liftot e na %d sprat\n",l->sprat);
  30.         }
  31.     }
  32.     else if(p->sprat<l->sprat)
  33.     {
  34.         l->sostojba=2;
  35.         while(l->sprat>p->sprat)
  36.         {
  37.             (l->sprat)--;
  38.             printf("Liftot e na %d sprat \n",l->sprat);
  39.         }
  40.     }
  41.     l->sostojba=0;
  42.     printf("Liftot pristigna\n");
  43.     if((l->brpatnici)>MAXPATNICI)
  44.     {
  45.         printf("Liftot ne moze da primi povekje patnici!!!!!\n");
  46.     }
  47.     else
  48.     {
  49.         (l->brpatnici)++;
  50.         if(l->sprat<p->kade)
  51.         {
  52.             l->sostojba=1;
  53.             while(l->sprat<p->kade)
  54.             {
  55.                 (l->sprat)++;
  56.                 printf("Liftot e na %d sprat",l->sprat);
  57.             }
  58.         }
  59.         else if(l->sprat>p->kade)
  60.         {
  61.             l->sostojba=2;
  62.             while(l->sprat>p->kade)
  63.             {
  64.                 (l->sprat)--;
  65.                 printf("Liftot e na %d sprat",l->sprat);
  66.             }
  67.         }
  68.         (l->brpatnici)--;
  69.         (l->sostojba)=0;
  70.     }
  71. }
  72. intmain()
  73. {
  74. lift l={0,0,4};
  75. patnik p={3,2};
  76. povikajlift(&p,&l);
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement