O'Reilly logo

C Programming Absolute Beginner’s Guide, Third Edition by Dean Miller, Greg Perry

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

12. Juggling Several Choices with Logical Operators

Sometimes the relational operators described in Chapter 11, “The Fork in the Road—Testing Data to Pick a Path,” simply can’t express all the testing conditions. For example, if you wanted to test whether a numeric or character variable is within a certain range, you would have to use two if statements, like this:

if (age >= 21) /* See if 21 <= age <= 65 */{ if (age <= 65)    {    printf("The age falls between 21 and 65.\n");    }}

Although there’s nothing wrong with using nested if statements, they’re not extremely straightforward, and their logic is slightly more complex ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required