Problem-Solving

1. Develop an algorithm or write pseudocode to determine if a citizen is eligible to vote. The
criteria for eligibility are that the citizen must be 18 or older and must not be a convicted
felon. The algorithm must continuously accept as input only the names, year of birth and
felony status of a citizen. The algorithm should continue to accept this information until a
year of 0 (zero) is input.
Print the name of the citizen and a statement saying whether or not the citizen is eligible to
vote.
2. Design and execute a trace table that accepts citizen data and show the expected output.
The table should have at least ten citizens showing person meeting all possible outputs and
variations.
Program Implementation
3. Using the programming language Pascal, write program code to implement the algorithm
in (1) above.

Algorithm:

1. Start the algorithm.
2. Read the name, year of birth, and felony status of a citizen.
3. Check if the year of birth is 0.
a. If yes, exit the algorithm.
4. Calculate the age of the citizen by subtracting the year of birth from the current year.
5. Check if the age is greater than or equal to 18 and the felony status is "not guilty".
a. If yes, print the name of the citizen along with the message "is eligible to vote".
b. If no, print the name of the citizen along with the message "is not eligible to vote".
6. Repeat steps 2 to 5 until the year of birth is 0.

Pseudocode:
````
START Algorithm

yearOfBirth = 1

WHILE yearOfBirth != 0
READ name from user
READ yearOfBirth from user
READ felonyStatus from user

IF yearOfBirth != 0
age = currentYear - yearOfBirth

IF age >= 18 AND felonyStatus == "not guilty"
PRINT name + " is eligible to vote"
ELSE
PRINT name + " is not eligible to vote"

ENDIF

ENDWHILE

END Algorithm
````

Trace Table:
| Citizen | Year of Birth | Felony Status | Eligible to Vote? |
|---------|--------------|---------------|-------------------|
| John | 1990 | not guilty | Yes |
| Sarah | 2005 | not guilty | No |
| Mark | 2003 | guilty | No |
| Anna | 1985 | not guilty | Yes |
| Eric | 1970 | not guilty | Yes |
| Lisa | 1965 | guilty | No |
| David | 2002 | not guilty | No |
| Karen | 1999 | guilty | No |
| James | 1998 | not guilty | Yes |
| Emily | 1988 | not guilty | Yes |

Program Code in Pascal:
```
program EligibilityToVote;
var
name: array [1..100] of string;
yearOfBirth: array [1..100] of integer;
felonyStatus: array [1..100] of string;
currentYear, age, i: integer;
begin
currentYear := 2022; // Assign the current year

i := 1;
repeat
begin
writeln('Enter the name of the citizen:');
readln(name[i]);
writeln('Enter the year of birth (0 to exit):');
readln(yearOfBirth[i]);
if (yearOfBirth[i] = 0) then
break;
writeln('Enter the felony status (not guilty/guilty):');
readln(felonyStatus[i]);

age := currentYear - yearOfBirth[i];

if (age >= 18) and (felonyStatus[i] = 'not guilty') then
writeln(name[i], ' is eligible to vote.')
else
writeln(name[i], ' is not eligible to vote.');

i := i + 1;
end;
until (yearOfBirth[i] = 0);

writeln('End of program.');

readln;
end.
```

Note: The program code provided is in Pascal programming language. You can compile and execute it using a Pascal compiler.