Validating Input

If you haven't done so already, run the program while giving deliberately bad input from the human. Try giving:

In this step you will change your program so that it insists on valid input. When working correctly your program should behave LIKE THIS.

The best solution is to modify the prompt procedure so that it takes a procedure as a second parameter that can be applied to the user input for validity. A third parameter specifies the string to display when the input is invalid:

  (define prompt
    (lambda (prompt-string valid? error-string)  ; note added parameters
      ...))
When the input fails the test, the error string should be displayed and the original prompt should be repeated (use iteration).

To test for non-numerical input, use the built-in integer? predicate, which takes an argument and tests for whether it is an integer.