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?".
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)