Ainsworth Computer Seminar
Flowcharts - a computer road map

I use diagrams like this when I am designing software because they allow me to visualize the program as I am creating it. The program shown here as a flowchart and below in actual computer instructions is a classic example of a computer program.

FlowchartIt isn't hard to see what the computer will do when this program runs. The diamond-shaped boxes show where the computer will make decisions. If the answer is "yes" to the computer's question, the program flow is to the right of the diamond. If it's "no," the flow continues downward in this diagram.


Try it yourself -- run the Guessing Game program

WARNING! Read the instructions before you run the program.

This is a very simple computer program with only 14 instructions. It is not "user friendly" and does not have a built-in help system. If you run this program, you will have to guess the correct number before the program ends and returns you to this page. Remember to press the Enter key each time after you type a number or a letter. When you guess correctly, the computer will ask if you wish to go again. Type "N" and press the Enter key to return to this page.

Run the Guessing Game program.


Computer code -- the words for it

Now for the details. This is what the computer instructions look like for the Guessing Game program. You can "read" these instructions (called "commands" by programmers) and see how this software works. The computer instructions are followed by an "English" translation of what they do.

'Guessing Game
RANDOMIZE TIMER
CLS
PRINT "Guess a number between 1 and 10"
Answer = INT(RND * 10) + 1
More:
INPUT "Your guess: ", Guess
PRINT Guess;
IF Guess < Answer THEN PRINT " is too low": GOTO More
IF Guess > Answer THEN PRINT " is too high": GOTO More
PRINT " is right!"
INPUT "Try again? (y/n)", Again$
IF Again$ = "y" OR Again$ = "Y" THEN RUN
END

And here's the English explanation of what the computer does at each step:

'Guessing Game
The first line is the title of the program. When a line begins with a single quotation mark, the computer ignores this instruction. This way, you can add titles and comments anywhere in your program without confusing the computer.

RANDOMIZE TIMER
You first RANDOMIZE TIMER so that your computer can pick random numbers.

CLS
The computer clears the screen.

PRINT "Guess a number between 1 and 10"
The computer prints: "
Guess a number between 1 and 10"

Answer = INT(RND * 10) + 1
The computer picks a random number and sets Answer equal to that number.

More:
A word followed by a colon is used as a label. This allows the computer to go to a specific place in the program.

INPUT "Your guess: ", Guess
This instruction does two things. It prints "Your guess:" on the screen, followed by a question mark. When you type a number and press the Enter key, Guess is set equal to the number you guessed.

PRINT Guess;
The computer prints the number you entered.

Now the computer compares the value of Answer and the value of Guess to decide what to do next.
IF Guess < Answer THEN PRINT " is too low": GOTO More
IF Guess > Answer THEN PRINT " is too high": GOTO More

If Guess is more > or less < than Answer, the program prints a response and goes back to the label More and continues from there.

PRINT " is right!"
If your answer isn't too low or too high, it must be correct.

INPUT "Try again? (y/n)", Again$
The program asks for another input, and this time it sets Again$ equal to the letter you type.

IF Again$ = "y" OR Again$ = "Y" THEN RUN
If your letter is "y" or "Y", the program runs again from the beginning

END
If not, the program stops.


Things to do

This program was created in the computer programming language, QuickBASIC. If you have this language on your computer, you can run the original program and make any changes or improvements you would like.

If you don't know how to do this and would like to learn, I have a special section just for you. Try Really really basic BASIC and get a short course in programs and even write one yourself. Then you can open and run this program or any other program you may want to see in detail, modify, or use as the basis for creating something new.

It isn't hard to find several things you might want to do to improve the Guessing Game program. For example, to change the range of numbers you have to guess, just change the number ten in the instruction that sets Answer to a random number. If you substitute 100, the person running this program will have to guess a number between one and a hundred.

This would make the program much more challenging, but it might make it too difficult for very young people who might run your improved version. If you change the range, you should also change this statement so that the instructions match your new program.


Seminar homewww.qwerty.com