Which change repairs the damaged-item counter?
An algorithm is a step-by-step procedure for carrying out a task. The algorithm below should count all damaged items in a finite list. Every item’s Damage Status is Yes or No. For an empty list, the required count is 0.
The draft below is incorrect. For the statuses Yes, No, Yes, it outputs 1 although the required count is 2.
The steps use pseudocode, a way to describe instructions with words and structured lines. Input names the information supplied; Output names the result to report. You can follow the steps by hand.
Which single change makes the algorithm correct for every permitted list? Leave all other instructions unchanged.
- Move
Set Damaged Count to 0inside theIf, immediately before adding1. - Move
Set Damaged Count to 0afterEnd For, immediately before the output. - Change
Damaged Count + 1toDamaged Count + 2. - Move
Set Damaged Count to 0immediately afterStart, beforeFor each.