Previous page Next page Navigation bar

Calculator Programming Tutorial

Programming Building Blocks I

Control Flow I

Alternatives Flowchart Descriptions

Algorithm

In the Control Flow Alternatives page, a flowchart describes the algorithm under discussion. The algorithm in text form is as follows:

  1. Start.
  2. Test whether the coefficient a is zero. If so, continue with step 4.
  3. Assign (-b + sqrt (b2 4ac))/2a to x1. Assign (-b sqrt (b2 4ac))/2a to x2. Continue with step 9.
  4. Test whether the coefficient b is zero. If so, continue with step 6.
  5. Assign b/c to x. Continue with step 9.
  6. Test whether the coefficient c is zero. If so, continue with step 8.
  7. Print “no solution.” Continue with step 9.
  8. Assign 0 to x.
  9. End.
Structure of Alternative

In the Control Flow Alternatives page, a flowchart fragment demonstrates the structure of the alternative construct. The construct consists of three flowchart symbols: a diamond, representing a decision; and two rectangles, representing processing.

The diamond is on the centerline of the diagram, with the two rectangles lower than the diamond, arranged symmetrically around the centerline. A short arrow leads into the top of the diamond. The diamond contains the text “condition.” An arrow goes out from either side vertex of the diamond; one arrow has the label “true,” the other the label “false.” Each arrow goes horizontally away from the diamond for a short distance, then goes down to the rectangle under it.

The rectangle reached through the arrow with the label “true” contains the text “Alternative for condition true.” The rectangle reached through the arrow with the label “false” contains the text “Alternative for condition false.”

Each of the processing rectangles has an arrow coming from the bottom of the rectangle. The arrows go down away from the rectangle for a short distance, then turns and heads to the centerline of the diagram. The arrows meet at the centerline of the diagram, where a third short arrow goes down.

Example of Alternative

In the Control Flow Alternatives page, a flowchart fragment gives an example of a set of alternative constructs that compute the smaller positive root of a quadratic equation guaranteed to have at least one positive root. The algorithm fragment is as follows:

  1. The value r is computed as the square root of b2-4ac.
  2. The value t1 is computed as (-v-r)/a; the value t2 is computed as (-v+r)/a.
  3. The condition t1 < t2 is evaluated; if true, proceed with step 4; if false, proceed with step 5.
  4. The value tmin is computed as t1; tmax, as t2. Proceed with step 6.
  5. The value tmin is computed as t2; tmax, as t1.
  6. The condition tmin > 0 is evaluated; if true, proceed with step 7; if false, proceed with step 8.
  7. The value t is computed as tmin. Proceed with step 9.
  8. The value t is computed as tmax.
  9. [The algorithm continues.]

Click here to return to the alternatives page.

[ Previous page | Top of page | Next page ]

Previous page Top of page Next page Navigation bar

Copyright © 2001 Brian Hetrick
Page last updated 30 December 2001.

Brian’s Casio Calculator Corner

Home

Programs

Tutorial

Preface

Introduction

Fundamentals

Building Blocks I

Introduction

Comments

Data Types

Numbers

Variables

Expressions

Control Flow I

Introduction

Sequences

Alternatives

Loops

Composition

Control Flow II

Subprograms

Basic I/O

Algorithms

A First Program

Examples

Exercises

Answers

Modularization

Data Structures I

Recursion

Program Attributes

Building Blocks II

Algorithm Analysis

Structuring

Data Structures II

Abstract Types

Objects

Problem Analysis

Reference Card

References

Puzzles

Site Information

Your Privacy

Site Map

E-mail

Site Technical Data