-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq9.c
77 lines (56 loc) · 2.05 KB
/
q9.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Write a login program in C that ask the user to enter his ID and his password, if the ID is
// correct the system will ask the user to enter his password up to 3 times,if he enters the
// password right the systems welcomes him, if the three times are incorrect, the system print
// No more tries. If the user ID is incorrect the system print You are not registered.
// user id pass
// Ahmed 1234 7788
// Amr 5678 5566
// wael 9870 1122
#include <stdio.h>
int main() {
int user_id;
int entered_passwd, attempt = 1;
printf("Enter your ID: ");
scanf("%s", user_id);
switch (user_id) {
case 1234:
do {
printf("Enter your password (attempt %d/3): ", attempt);
scanf("%d", &entered_passwd);
if (entered_passwd == 7788) {
printf("Welcome, Ahmed!\n");
return 0;
}
attempt++;
} while (attempt <= 3);
printf("No more tries.\n");
break;
case 5678:
do {
printf("Enter your password (attempt %d/3): ", attempt);
scanf("%d", &entered_passwd);
if (entered_passwd == 5566) {
printf("Welcome, Amr!\n");
return 0;
}
attempt++;
} while (attempt <= 3);
printf("No more tries.\n");
break;
case 9870:
do {
printf("Enter your password (attempt %d/3): ", attempt);
scanf("%d", &entered_passwd);
if (entered_passwd == 1122) {
printf("Welcome, wael!\n");
return 0;
}
attempt++;
} while (attempt <= 3);
printf("No more tries.\n");
break;
default:
printf("You are not registered.\n");
}
return 0;
}