So far, all the programs you've seen have been pretty simple. The idea of planning any of them
Programming is a lot like construction. So, imagine a contractor building a house for you without a blueprint. Yikes! You're liable to end up with a house that has 12 bathrooms, no
Programming is the same way. Without a plan, you'll likely struggle through the process, wasting time. You might even end up with a program that doesn't quite work.
Program planning is so important that there's an entire field of software engineering dedicated to it. But even a beginning programmer can benefit from a few simple planning tools and techniques.
An algorithm is a set of clear, easy-to-follow instructions for accomplishing some task. An algorithm is like a blueprint for your program. It's something you planned out, before programming, to guide you along as you code.
An algorithm isn't just a goal—it's a concrete list of steps to be followed in order. So, for example, "Be a millionaire" is not really an algorithm. It's more like a goal. But a worthy one. So I wrote the Make a Million Dollars algorithm. Here it is:
{% if main.adsdop %}{% include 'adsenceinline.tpl' %}{% endif %}
if you can think of a new and useful product then that's your productotherwise repackage an existing product as your product make an infomercial about your product show the infomercial on TV charge $100 per unit of your product sell 10,000 units of your product
There you go. It's a clear series of finite steps that can be followed to achieve the goal.
Algorithms are
Like any outline or plan, your algorithm might not be finished after one draft. Often, algorithms need multiple
create an infomercial about your product
This might seem like too vague a task. How do you create an infomercial? Using stepwise refinement, the single step can be broken down into several others. So, it becomes the following:
write a script for an infomercial about your product rent a TV studio for a day hire a production crew hire an enthusiastic audience film the infomercial
If you feel that these five steps are clear and achievable, then that part of the algorithm has been thoroughly refined. If you're still unclear about a step, refine it some more. Continue with this process and you will have a complete algorithm and a million dollars.