Back to DFS's Turing Page


Flowcharting an Algorithm

The Problem

Calculate and output the area of a triangle using dimensions provided by the user.

The Algorithm & Pseudocode

This problem is more complex than the first Triangle-Area problem, because we have to get information from the user. To accomplish the task, we need to let the user know what the program does and we have to request that the user input the data. Then we can carry on just as we did in the previous problem.

  1. Introduction: Let the user know what the program does and what he/she needs to do.
  2. Obtain the dimensions of the triangle from the user, assigning the values to appropriate variables.
  3. Calculate the area using the standard formula: A = 1/2bh.
  4. Print the result in a grammatical English sentence.

Step 1 can be broken down into many individual steps. Here we will use two:
    1a. Tell the user what the program does.
    1b. Tell the user what he/she needs to do.

The flowchart segment in Diagram B at the right shows the two steps as being included inside Step 1.

Step 2 is more complicated: we need to get two values from the user - the one for the base and the one for the height. This is shown in Diagram C by drawing two process boxes inside box 2.

Inside each one of these boxes, the program has to prompt the user (tell the user to type in a value) and then read in what is typed. Diagram D illustrates how each of these boxes would be redrawn.

The resulting more specific flowchart is given in Diagram E and the corresponding, detailed pseudocode is found below.

1. Introduction:
    a. Tell the user what the program does.
    b. Tell the user what he/she needs to do.
2. Obtain the dimensions of the triangle:
    a. Base:
        i. Prompt for value
        ii. Read in value
    b. Height:
        i. Prompt for value
        ii. Read in value
3. Calculate the area using the standard formula: A = 1/2bh.
4. Print the result in a grammatical English sentence.


© 1997-2004 DFStermole
HTMLified: 29 Dec 99
Last Modified: 17 Feb 2004