# Associate Program Material

Associate Program Material

Appendix J

Algorithm Verification

Consider the following selection statement, where testScore is an integer test score between 0
and 100.

declare testScore as Integer; values 0-100
input testScore
if (0 <= testScore and testScore < 49)
output “You fail.”
else if (50 <= testScore and testScore < 70)
output “You did OK.”

else if (70 <= testScore and testScore < 85)
output “You did well.”
else if (85 <= testScore and testScore < 100)
output “You did great.”
endif
output “How did you do?”

• What will be printed if the input is 20?
“You Fail.” Will be printed because:
if (0 <= testScore and testScore < 49)
output “You fail.”
• What will be printed if the input is 100?
“How did you do?” will be printed.

• What will be printed if the input is 73?
else if (70 <= testScore and testScore < 85)
output “You did well.”

• What will be printed if the user enters “score”?
“score” Will cause an error. “How did you do?” could be printed again

• Is this design robust? If so, explain why. If not, explain what you can do to make it robust.
This design is not robust because there is no statement for error or exception handling. To
make it more robust I would add a statement like the user can only enter integers from 0
to 100. If the user enters other numbers or data types they will get an error or an invalid
message such as like “Invalid entry. Enter a number from 0 to 100” It also doesn’t handle the
case of entering 49. It should be: else if (49 <= testScore and testScore < 70), because as it is
now, when 49 is entered all it will say is “How did you do?” The same thing will happen when
entering 100, else if (85 <= testScore and testScore <= 100) would fix this problem.

How many levels of nesting are there in this design?

Appendix J
IT/210 Version 5

There is no nesting.
• Provide a set of values that will test the normal operation of this program segment. Defend