-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathamt4.awk
More file actions
50 lines (42 loc) · 1.8 KB
/
amt4.awk
File metadata and controls
50 lines (42 loc) · 1.8 KB
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
#!/usr/bin/awk -f
# Function to validate input (ensures only 0 or 1 is entered)
function get_valid_input(prompt, regex, value) {
while (1) {
printf "%s", prompt;
getline value < "-"; # Read input from the user
if (value ~ regex) {
return value; # Return valid input
} else {
print "Invalid input! Please enter 0 for correct or 1 for incorrect.";
}
}
}
BEGIN {
# Introduction
print "AMT4 (Abbreviated Mental Test) Calculator";
print "This test evaluates cognitive impairment using 4 simple questions.";
print "For each question, enter 0 for correct and 1 for incorrect.";
print "----------------------------------------";
# Initialize total score
total_score = 0;
# Prompt for each question and validate input
q1 = get_valid_input("Question 1: Age (0 for correct, 1 for incorrect): ", "^(0|1)$");
total_score += q1;
q2 = get_valid_input("Question 2: Date of birth (0 for correct, 1 for incorrect): ", "^(0|1)$");
total_score += q2;
q3 = get_valid_input("Question 3: Current year (0 for correct, 1 for incorrect): ", "^(0|1)$");
total_score += q3;
q4 = get_valid_input("Question 4: Place (name of hospital, building, or location) (0 for correct, 1 for incorrect): ", "^(0|1)$");
total_score += q4;
# Display total score and interpretation
print "----------------------------------------";
print "Total AMT4 Score: " total_score;
if (total_score == 0) {
print "Interpretation: No cognitive impairment.";
} else if (total_score >= 1 && total_score <= 2) {
print "Interpretation: Possible mild cognitive impairment.";
} else {
print "Interpretation: Likely significant cognitive impairment.";
}
exit;
}