Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- //Open the door
- void open_door()
- {
- printf("\nOpening the door!");
- }
- //Ask the two questions
- void questions()
- {
- int code1 = 0;
- int code2 = 0;
- printf("\nWhat is the first code ? ");
- scanf("%d", &code1);
- if(code1 == 1)
- {
- printf("Valid code!\n");
- }
- else if(code1 != 1)
- {
- printf("Unvalid code!\n");
- return ;
- }
- printf("\nWhat is the second code ? ");
- scanf("%d", &code2);
- if(code2 == 22)
- {
- printf("Valid code!\n");
- }
- else if(code2 != 22)
- {
- printf("Unvalid code!\n");
- return ;
- }
- }
- //Enter the code
- void code()
- {
- int code_card = 0;
- printf("\nPlease enter the code of the card : ");
- scanf("%d", &code_card);
- if(code_card == 1234)
- {
- printf("Valid code!\n");
- }
- else if(code_card != 1234)
- {
- printf("Unvalid code!\n");
- return ;
- }
- }
- //Scan the retine (ask the name)
- void scan()
- {
- char name[100], name2[] = "Pierre";
- printf("\nPlease enter your name : ");
- scanf("%s", name);
- if (strcmp(name, name2) == 0)
- {
- printf("Valid name!\n");
- }
- else
- {
- printf("Unvalid name!\n");
- }
- }
- //Choose the card
- void card_id ()
- {
- int card_number = 0;
- printf("Please enter the card number : ");
- scanf("%d", &card_number);
- switch (card_number)
- {
- case 0 :
- open_door();
- break;
- case 1 :
- questions();
- open_door();
- break;
- case 2 :
- code();
- open_door();
- break;
- case 3 :
- questions();
- code();
- open_door();
- break;
- case 4 :
- scan();
- open_door();
- break;
- case 5 :
- scan();
- questions();
- open_door();
- break;
- case 6 :
- scan();
- code();
- open_door();
- break;
- case 7 :
- scan();
- questions();
- code();
- open_door();
- break;
- default :
- printf("\nUnvalid card!");
- }
- }
- int main() {
- card_id();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment