Answer:

Yes. The progam can be written without any if statements. It could use just a single while statement that tests a fairly complicated boolean expression. The user would enter each of the three numbers before any are tested.

Sample Run

It would be a fruitful exercise for you to shorten the program as suggested. Programmers usually continue working on a program after it first meets the specifications. Often the program will shrink in size as work continues! (But a program should not be made shorter at the expense of simplicity and clarity.)

Here is a sample run of our simple and clear program:

Enter first number: 6
Enter second number: 15
Enter third number: 30
Lock does not open

Enter first number: 6
Enter second number: 12
Enter third number: 30
Lock opens

QUESTION 14:

Do actual locks insist that each number be entered exactly correct?