42.1k views
2 votes
The following names of students are stored in an array with the identifier studentnames.

studentnames = ["Rob", "Anna", "Huw", "Emma", "Patrice", "Iqbal"]

Write an algorithm using iteration to:

· display the name of each student one at a time from studentnames
· take as input whether that is present or absent
· display the total number of present students or number of absent students in a suitable message, after all student names have been displayed

1 Answer

3 votes

Answer:

1. Set the variable present_count to 0 and absent_count to 0

2. For each student in studentnames:

a. Display the name of the student

b. Take input whether the student is present or absent

c. If the student is present, increment present_count by 1

d. If the student is absent, increment absent_count by 1

3. Display the total number of present students and absent students in a suitable message:

a. "Number of present students: " + present_count

b. "Number of absent students: " + absent_count

User JJoao
by
7.5k points

Related questions