[prog] validate input

Dominik Schramm dominik.schramm at gmxpro.net
Mon Dec 22 13:24:22 EST 2003


Some additions/corrections:

On 12/22/2003 12:00 PM, Dominik Schramm wrote:

>So here's the structure chart:
>[...]
>
>+------------------------------------------------------+
>| while "counter" is at most 10 do                     |
>+   +--------------------------------------------------+
>|   | say "input 1 for 'passed' or 2 for 'failed'"     |
>|   +--------------------------------------------------+
>|   | get "result" from user                           |
>|   +--------------------------------------------------+
>|   |               "result" is 1?                     |
>|   | yes:                no:                          |
>|   +-------------------+------------------------------+
>|   | increase "ctPass" |         "result" is 2?       |
>|   | by 1              | yes:           no:           |
>|   +-------------------+--------------+---------------+
>|   | increase "counter"| increase     | say "invalid  |
>|   | by 1              | "ctFail" by 1| input, try    |
>|   |                   +--------------+ again!"       |
>|   |                   | increase     |               |
>|   |                   | "counter"    |               |
>|   |                   | by 1         |               |
>+---+-------------------+--------------+---------------+
>

Here's how to read this:
Everything in the same "column" up to the ending vertical
line from the very left to very right is executed sequentially.
If a line contains several columns, these columns are
executed alternatively, either column 1 or column 2, etc.
A rectangle with something written in the top line and with
the top line extended vertically down the left side (see
"while" above) is a control structure, i.e. the inside rectangle
is somehow controlled by what the top line says (in this
case: "while" something is true, do what the inside rectangle
says; same for "for").
A decision (like "result is 1?" above) is actually written like
this:
+-----------+
|\condition/|
| \ true? / |
|  \     /  |
|   \   /   |
|yes \ / no |
+-----+-----+
|     |     |
| yes | no  |
|part | part|
|     |     |
+-----+-----+

This just would have been awkwardly long (vertically) to draw
in this case.

>[...]  
>   while (counter <= 10)
>    {
>        cout << "input 1 for 'passed' or 2 for 'failed'" << endl;
>        cin >> input;
>  
>

this should be "cin >> result;" of course.

dominik





More information about the Programming mailing list