134k views
1 vote
You have just starting working at Quantum Company. As a new programmer, you have been asked to review and correct various pseudocode. The following pseudocode checks if an item number is valid: start Declarations num sub = 0 num SIZE = 5 num VALID_ITEM [5] = 27,53,84,89,95 string foundIt = "N" input item while sub < SIZE if item = VALID_ITEM[sub] then foundIt = "Y" endif sub = sub +1 endwhile if foundIt = "Y" then output "Valid item number" else output "Invalid item number" endif stop Which while loop makes this more efficient?

1 Answer

3 votes

Answer:

The correct answer to the following question:

while sub < SIZE AND foundIt = "N"

Explanation:

Firstly, we start the pseudocode after that set the variable sub to 0 and size to 1 of num type and also set a num type array VALID_ITEM[5] and its elements are 27,53,84,89,95.

Than set string type variable foundIt to "N", then we set a while loop and correct its condition is "< SIZE AND foundIt = "N" ".

Than starts if condition which is "item = VALID_ITEM[sub]", if the condition is true than foundIt = "Y", after that endif.

Than increment the variable sub, after that endwhile, after this, we start if condition which is "foundIt = "Y" " if the condition is true then output "Valid item number" or else "Invalid item number", and then we endif and after all stop the pseudocode.

User Jostein Topland
by
5.7k points