You have seen how the `else`

statement comes into play when you have a test against two possible conditions: Either the number is even or it is odd; either the year is a leap year or it is not. However, programming decisions you have to make are not always so black and white. Consider the task of writing a program that displays `–1`

if a number the user types is less than zero, `0`

if the number is equal to zero, and `1`

if the number is greater than zero. (This is actually an implementation of what is commonly called the *sign* function.) Obviously, you must make three tests in this case to determine whether the number that is keyed in is negative, zero, or positive. The simple `if-else`

construct will not work. Of course, in this ...

Start Free Trial

No credit card required