Xynea

Untitled

Nov 16th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4.  
  5. //Open the door
  6. void open_door()
  7. {
  8.     printf("\nOpening the door!");
  9. }
  10.  
  11.  
  12. //Ask the two questions
  13. void questions()
  14. {
  15.     int code1 = 0;
  16.     int code2 = 0;
  17.    
  18.     printf("\nWhat is the first code ? ");
  19.     scanf("%d", &code1);
  20.    
  21.     if(code1 == 1)
  22.     {
  23.         printf("Valid code!\n");
  24.     }
  25.    
  26.     else if(code1 != 1)
  27.     {
  28.         printf("Unvalid code!\n");
  29.         return ;
  30.     }
  31.    
  32.     printf("\nWhat is the second code ? ");
  33.     scanf("%d", &code2);
  34.    
  35.     if(code2 == 22)
  36.     {
  37.         printf("Valid code!\n");
  38.     }
  39.    
  40.     else if(code2 != 22)
  41.     {
  42.         printf("Unvalid code!\n");
  43.         return ;
  44.     }
  45. }
  46.  
  47.  
  48. //Enter the code
  49. void code()
  50. {
  51.     int code_card = 0;
  52.    
  53.     printf("\nPlease enter the code of the card : ");
  54.     scanf("%d", &code_card);
  55.    
  56.     if(code_card == 1234)
  57.     {
  58.         printf("Valid code!\n");
  59.     }
  60.    
  61.     else if(code_card != 1234)
  62.     {
  63.         printf("Unvalid code!\n");
  64.         return ;
  65.     }
  66. }
  67.  
  68.  
  69. //Scan the retine (ask the name)
  70. void scan()
  71. {
  72.     char name[100], name2[] = "Pierre";
  73.  
  74.     printf("\nPlease enter your name : ");
  75.     scanf("%s", name);  
  76.    
  77.     if (strcmp(name, name2) == 0)
  78.     {
  79.         printf("Valid name!\n");
  80.     }
  81.     else
  82.     {
  83.         printf("Unvalid name!\n");
  84.     }
  85. }
  86.  
  87.  
  88. //Choose the card
  89. void card_id ()
  90. {
  91.     int card_number = 0;
  92.    
  93.     printf("Please enter the card number : ");
  94.     scanf("%d", &card_number);
  95.    
  96.     switch (card_number)
  97.     {
  98.         case 0 :
  99.             open_door();
  100.             break;
  101.            
  102.         case 1 :
  103.             questions();
  104.             open_door();
  105.             break;
  106.        
  107.         case 2 :
  108.             code();
  109.             open_door();
  110.             break;
  111.            
  112.         case 3 :
  113.             questions();
  114.             code();
  115.             open_door();
  116.             break;
  117.            
  118.         case 4 :
  119.             scan();
  120.             open_door();
  121.             break;
  122.            
  123.         case 5 :
  124.             scan();
  125.             questions();
  126.             open_door();
  127.             break;
  128.            
  129.         case 6 :
  130.             scan();
  131.             code();
  132.             open_door();
  133.             break;
  134.            
  135.         case 7 :
  136.             scan();
  137.             questions();
  138.             code();
  139.             open_door();
  140.             break;
  141.            
  142.         default :
  143.             printf("\nUnvalid card!");
  144.     }
  145. }
  146.  
  147.  
  148.  
  149. int main() {
  150.     card_id();
  151.    
  152.     return 0;
  153. }
Advertisement
Add Comment
Please, Sign In to add comment