-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcovid_tracker.c
74 lines (62 loc) · 1.88 KB
/
covid_tracker.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
#include <stdio.h>
#include <string.h>
#define MAX_USERS 10
#define MAX_NAME_LENGTH 50
#define MAX_PASSWORD_LENGTH 10
#define MAX_QUESTIONS 8
typedef struct {
char name[MAX_NAME_LENGTH];
char password[MAX_PASSWORD_LENGTH];
int covid_symptoms;
int covid_points;
} User;
// Global array of users
User users[MAX_USERS];
int userCount = 0;
void trackSymptoms(int userIndex) {
const char* questions[MAX_QUESTIONS] = {
"Have you had any fever recently? (Y/N): ",
"Do you find yourself with a runny nose? (Y/N): ",
// Add other questions here
};
int points[MAX_QUESTIONS] = {30, 30 /*, ... other points */};
char answer;
printf("Answer the following questions with 'Y' for yes or 'N' for no.\n");
for (int i = 0; i < MAX_QUESTIONS; i++) {
printf("%s", questions[i]);
scanf(" %c", &answer); // Space before %c to skip any whitespace
if (answer == 'Y' || answer == 'y') {
users[userIndex].covid_symptoms++;
users[userIndex].covid_points += points[i];
}
}
}
int main() {
char login[MAX_NAME_LENGTH], password[MAX_PASSWORD_LENGTH];
while (1) {
printf("What is your name?: ");
scanf("%s", login);
int userIndex = -1;
for (int i = 0; i < userCount; i++) {
if (strcmp(users[i].name, login) == 0) {
userIndex = i;
break;
}
}
if (userIndex != -1) {
printf("What is your four-digit password?: ");
scanf("%s", password);
if (strcmp(users[userIndex].password, password) == 0) {
trackSymptoms(userIndex);
break;
} else {
printf("Incorrect password.\n");
break;
}
} else {
printf("User not found.\n");
break;
}
}
return 0;
}