Zyra's website //// Computers //// Computer Programming Explained //// Site Index

Computer Programming Example Easily Explained

In the page of computer programming easily explained, I brought the idea of programming into the real world by using a science fiction scenario of a household robot that could follow simple instructions on a list, termed a "computer program". Although as yet in the zero-zeros decade robots have not been quite up to performing housework tasks, the sci-fi imaginary example shows you how you can be a computer programmer without having to be a boffin.

The principle is very similar in actual computers, as you command them using lists of commands, and even if they are limited physically they can still do robotic "mental arithmetic" so incredibly unbelievably fast and without error that this is very useful.

So now, after having got the household robot to do the housework and to shift a ton of sand from the front of the house to the back of the house with a wheelbarrow, let's get the robot to play a game. The Game of Guess the Number is not exactly grandmaster chess, but it is a game which computers can play against you, and it shows off the techniques of computer programming very well.

"Here you are, robot, here are your instructions to play me at Guess The Number": (remember, these are the instructions for the robot to play me at the game)

1. Think of a random number between 1 and 1000 and don't tell me it.
2. Ask me to guess what the number is. Say "What is your Guess?".
3. Listen to my answer.
4. If my answer is less than the number you thought of, say "Too Small" and then GOTO 2.
5. If my answer is more than the number you thought of, say "Too Big" and then GOTO 2.
6. Say "Well Done! You got the right answer!"

OK, that's a science fiction household robot's computer program to play the game of Guess the Number. Now moving into the factual reality, here's a real computer program to command a modern computer to do the same thing:

10. N=RND(1000)
20. PRINT"What is your Guess?";
40. IF A<N PRINT"Too Small" : GOTO 20
50. IF A>N PRINT"Too Big" : GOTO 20
60. PRINT "Well Done! You got the right answer!"

Notice the exact equivalence between the two programs. With the modern real computer you just have to put things in a particularly precise computer language way of saying it. The programming conventions are very easy to understand and you soon become familiar with them.

If you'd like to run this actual program on your computer, I suggest you download BBC Basic and put the program in. You'll see it works.

If you've arrived at this page before seeing computer programming, it's worth seeing.

More advanced computer programming can be found by having Linux and running the GCC compiler.