Decision Making

Read this chapter, which reviews how computers make decisions using if statements. As you read this tutorial, you will understand that sometimes it is important to evaluate the value of an expression and perform a task if the value comes out to be true and another task if it is false. In particular, try the simulated program under the heading "Simulated Program" to see how a different response is presented to the user based on if a number is positive or negative.

Pay special attention to the "More Than One Statement per Branch" header to learn how the 'else' statement is used when there is more than one choice.

17. Flowchart


Answer:

You could first divide the group into:

    1. children
    2. adults

And then divide the adults into:

    1. male adults
    2. female adults

Flowchart

We wish to perform two splits to divide integers into negative, zero, and positive. First zero and positives are split from the negatives, and then that group is further split.

ThreeWay

The flowchart shows how this works. One decision is nested inside the false branch of the first decision. A negative integer is correctly detected by the first decision. But a zero or positive integer goes through another decision to pick the correct category for it.

Question 17:

Are there other ways to do this?