Text conversion of a flowchart

Here’s an example flowchart that contains a two-way decision and displays the absolute difference between two numbers. We want to generate an execution sheet for this flowchart.

The flowchart above cannot be directly represented in the form of an execution sheet unless we convert it into text. We use if before the conditional expression in PS# 3, and PS# 4 is the subordinate instruction of PS# 3. This true branch subordination is indicated in the flowchart by shifting this step to the right of the main flow. The same fact is shown in text form by adding space at the start of PS# 4.

Note: The PS# column shows the sequence number of each instruction in the program.

We also need to convert the false branch of the flowchart to text form. We use else to indicate the separation of true and false branches in PS# 5, and PS# 6 is the subordinate of PS# 5. PS# 7 is the print instruction we are already familiar with. It’s neither a part of the true branch nor the false branch.

Execution sheet of decisions

Within the same program, we may see two scenarios of execution:

  • When a is greater than b.
  • When a is not greater than b.

We need to introduce another column, “State”, representing the conditional state. The conditional state tells us whether a condition is true or false. The value of a conditional state depends on the current value of the variables participating in the condition. The execution sheet of both scenarios is shown below.

Execution when a is greater than b

In the execution sheet below, the user provided 87 as the value of a and 35 as the value of b. Therefore, the condition is true as indicated in the newly introduced “State” column. This execution sheet demonstrates the selection of the true branch.

We have written PS# 7 after PS# 4 because the true branch executes and the false branch (PS# 5 and 6) does not. To demonstrate the order in which instructions are executed, we need to introduce another sequence number in the execution sheet. This is the execution sequence number, appearing in the “ES#” column on execution sheets and illustrated in the next subsection.

Execution when a is not greater than b

In the second execution sheet, the user provided 20 as the value of a and 46 as the value of b. Therefore, the condition is false as indicated in the “State” column. The newly introduced column, “ES#”, keeps track of the linear sequence for a decision during the execution of the program. This execution sheet demonstrates the selection of the false branch.

Execution sheet for decision practice

Let’s use a few simple examples to practice two-way flowcharting decisions.

Greater of two numbers

In the sample flowchart of a two-way decision, we want to find the difference between the two values input by the user. The difference is calculated by subtracting the smaller value from the larger one. We start by comparing both inputs from the user with the help of an if statement.

The statement if a > b returns true if a is greater than b, so we store it as max = a. The false branch of code is followed when a is not greater than b, so we store it as max = b. In the end, we display the value of max.

There are two possible paths through this flowchart, depending upon the values input by the user. The true and false paths lead to two different execution sheets.

In the figure above:

  • If the value of a is greater than b, then the true path is followed. This path is shown in the execution sheet on the right.
  • If the value of a is not greater than b, then the false path is followed. This path is shown in the execution sheet on the left.
Let us practice the above execution sheet with various input pairs.
First, type two integers in the input boxes below and press the 'Show' button to print the execution sheet.
For example,
if you type:
15
20
Then the execution sheet of the false path will be displayed.
if you type:
15
10
Then the execution sheet of the true path will be displayed.

Don’t divide by zero

In both mathematics and programming, we can’t divide by zero. We want to make sure that our programs have an appropriate solution if the user inputs 0 as a divisor.

The following flowchart requests the input of two integer values and checks the value of the divisor. When the value of the divisor is zero, we assume its value is 11 instead.

The new symbol !=, called not equal to, means the LHS is not equal to RHS.

In the figure above:

  • If the value of b is not equal to 0, then the true path is followed. This path is shown in the execution sheet on the right.
  • If the value of b is 0, then the false path is followed. This path is shown in the execution sheet on the left. Here, the expression result = a represents that we are dividing a by 11 rather than 00.
Let us practice the above execution sheet with various input pairs.
First, type two integers in the input boxes below and press the 'Show' button to print the execution sheet.
For example,
if you type:
4
2
Then the execution sheet of the true path will be displayed.
if you type:
4
0
Then the execution sheet of the false path will be displayed.

Multiple or not

The following flowchart requests two integer values as input, determines whether the second number is a multiple of the first, and prints either multiple or not multiple, accordingly.

We have used the symbol % to find the remainder of a divided by b.

In the figure above:

  • If the value of b is a multiple of a, then the true path is followed. This path is shown in the execution sheet on the right.
  • If the value of b is not a multiple of a, then the false path is followed. This path is shown in the execution sheet on the left.
Let us practice the above execution sheet with various input pairs.
First, type two integers in the input boxes below and press the 'Show' button to print the execution sheet.
For example,
if you type:
2
4
Then the execution sheet of the true path will be displayed.
if you type:
3
7
Then the execution sheet of the false path will be displayed.

Get hands-on with 1400+ tech skills courses.