14. Operations on Arrays
Problems Can Be Erroneous, Too!
What do you think would happen if a user of the previous program typed in a zero as the first value on input? The program would then be required to find the smallest value in a list containing no elements. What would the correct solution be in that case?
Actually, there would be no correct solution because the task described makes no sense. It could be said that the stated problem is not complete because it lacks an acceptable description of the result for some valid input data. That makes the given problem incorrectly stated.
To correct this, we could add to the given problem a sentence stating that the first value on input will not be zero. This correction makes the previous program a correct solution to the problem. The only downside is that if the user accidentally types a zero as the first value on input, all the hell will break loose.
The other way to fix this would be to add the following sentence to the problem: if the input list contains no elements, then the program should output "List is empty, terminating" and discontinue further calculations. Can you solve this version of the problem by making the necessary changes to the program?