When you are faced with the task of writing a program, the first thing to consider is the data you are required to process. Make a list of the input data--what are the items and what are the possible values of each? If the items have a kind of structure or pattern, draw a diagram to illustrate it. Then do the same for the output data. Study your two diagrams and try to see if they fit together. If they do, you are well on the way to designing your program.
Next, write the specification that the user will use. This might be a written specification, a HELP file or both.
Last of all, write your program.
Here is a little example:
Think about how you would write this program.
The computer starts off with:
Let's play a game! Type "Heads", "Tails",
or "Quit"
and press ENTER.
This means that there are four possible inputs:
And so the corresponding outputs should be:
And this sequence must be repeated indefinitely, ending with the return to CICS.
Now that you understand the specification, the input data and the output data, you are ready to write the program.
If you had started off by writing down some instructions without considering the data, it would have taken you longer.
Write the program. If you are careful, it should run the first time!
/* CON EXEC */
/* Tossing a coin. The machine is lucky, not the user */
do forever
say "Let's play a game! Type 'Heads', 'Tails'",
"or 'Quit' and press ENTER."
pull answer
select
when answer = "HEADS"
then say "Sorry! It was TAILS. Hard luck!"
when answer = "TAILS"
then say "Sorry! It was HEADS. Hard luck!"
when answer = "QUIT"
then exit
otherwise
say "That's not a valid answer. Try again!"
end
say
end