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.
2. Two-way Decisions
Answer:
On.
Two-way Decisions
The windshield wipers are controlled with an ON-OFF switch. The flowchart at right shows how this decision is made.
Start at the top of the chart then follow the line to the question:
is it raining?
The answer is either true or false.
- If the answer is true,
- follow the line labeled True,
- perform the instructions in the box "wipers on",
- follow the line to "continue".
- If the answer is false,
- follow the line labeled False,
- perform the instructions in the box "wipers off",
- follow the line to "continue".
Question 2:
How many ways can you go from "start" to "continue"?