MODULE 2 • LESSON 01
Every program you will ever write starts long before you type a line of code. It starts with a problem: something in the real world that is not the way it should be. In this lesson you will learn the four words that the whole of Module 2 is built on — problem, solution, algorithm and program — and see how they connect. You will also find out why programmers take the time to work out the logic of a program first, as a list of carefully ordered steps, instead of jumping straight into C.
You will drive a robot that does exactly what you tell it (and nothing more), put scrambled algorithm steps into the right order and watch what goes wrong when they are out of order, and then see one algorithm written three ways: as a narrative, as pseudocode with a flowchart, and finally as a C program that you can compile and run.
What you will learn
- What a problem is, and how to write a short, clear problem statement.
- What problem-solving and a solution mean, and why one problem usually has several possible solutions.
- What an algorithm is, why it is a problem-solving strategy, and its role and importance in the problem-solving process.
- What a program is, and how it differs from an algorithm.
- Why the logic of a program must be developed first, as logically sequenced instructions.
- How one algorithm (the average of a set of marks) is written in plain English, pseudocode, a flowchart and C.
Part 1: What is a problem?
In everyday speech a problem is anything that bothers us. In computer science we use a sharper idea. A problem is the difference, or gap, between the situation as it is now (the current state) and the situation we want (the desired state). If there is no gap, there is nothing to solve. If we cannot say what the desired state is, we cannot tell when we have solved the problem.
| Current state | Desired state | The problem (the gap) |
| The school canteen sells out of patties by 10:15 a.m. and many students go hungry. | Every student who wants a patty at lunch can get one, with little waste. | The canteen does not know how many patties to make each day. |
| A maxi-taxi driver counts fares in his head and is often short at the end of the day. | The driver knows exactly how much money was collected on every trip. | There is no reliable record of the fares collected. |
| Teachers add up three test marks for 120 students by hand to get averages. | Averages are produced quickly and without arithmetic mistakes. | Working out averages by hand is slow and error-prone. |
Notice that each problem is about a situation, not about a computer. The canteen problem is not “we need an app”. An app might be part of a solution, but the problem itself is the mismatch between how many patties are made and how many are wanted. Keeping the problem separate from any particular solution stops you from settling on the first idea that comes to mind.
Problems and symptoms
Students hungry at lunch is a symptom. The underlying problem is that the canteen cannot predict demand. If you only treat the symptom (for example, by telling students to bring lunch from home) the real problem stays. A good problem solver keeps asking “why is this happening?” until the cause is clear. This becomes important in Lesson 03, where problem definition is the first stage of the problem-solving process.
Writing a problem statement
A problem statement is one or two sentences that say precisely what the problem is, who it affects and what the desired result is. It should be short, specific and free of any particular solution.
Worked example. Turn the third row of the table into a problem statement.
- Too vague: “Marks are a problem.” (Which marks? What is wrong with them?)
- Contains a solution: “The school needs an Excel spreadsheet for marks.” (That is one possible answer, not the problem.)
- Good: “Form 6 teachers spend several hours each term working out students’ average marks by hand, and the results sometimes contain arithmetic errors. Teachers need averages that are produced quickly and accurately.”
The good version names who is affected, describes the current state, and states the desired state in a way that can be checked later: were the averages produced quickly, and were they correct?
Part 2: Problem-solving and solutions
Problem-solving is the process of working out how to move from the current state to the desired state. A solution is a method (a plan, procedure or system) that, when carried out, removes the gap. Solutions do not have to involve computers at all: the canteen could simply keep a notebook of daily sales and use last week’s numbers to decide how many patties to bake.
Most problems have several possible solutions. For the averages problem you might:
- use a calculator more carefully (cheap, but still slow);
- set up a spreadsheet with an AVERAGE formula (fast, but someone must type every mark);
- write a small program that reads the marks from a file and prints every average (fast, accurate, and reusable each term).
Choosing between solutions means weighing things like cost, time, accuracy and how easy each one is to use. You will do that formally in Lesson 03. For now, the key idea is that the solution is what you will do, stated as an idea. To make a computer carry it out, the idea has to be turned into an algorithm, and then into a program.
Part 3: Algorithms
An algorithm is a finite, ordered sequence of clear, unambiguous steps that solves a problem or completes a task. Each word in that definition matters:
- Finite: it has a limited number of steps and it stops.
- Ordered: the steps are carried out in a definite sequence (with decisions and repeats where needed).
- Clear and unambiguous: each step has exactly one meaning, so anyone (or any computer) following it does the same thing.
- Solves the problem: following the steps from start to finish produces the desired result for every valid input, not just one lucky case.
Lesson 4 looks at these properties in detail. A cake recipe, the directions from your school to the beach, and the instructions for topping up a phone are all algorithms written for people. People can cope with vague steps like “bake until golden” because they bring their own judgement. A computer has no judgement, so an algorithm meant for a computer must spell out everything.
An algorithm as a problem-solving strategy
Writing an algorithm is a way of thinking through a problem. When you force yourself to list the exact steps, gaps in your understanding show up immediately: What happens if the list of marks is empty? Do we divide by the number of marks or by 3? Where does the input come from? Answering those questions is problem-solving. That is why the syllabus calls the algorithm a problem-solving strategy, not just a step on the way to code.
The role and importance of algorithms
| Role | Why it matters |
| A plan for the program | The programmer works out what to do before deciding how to say it in a language. Getting the logic right first saves hours of debugging. |
| Language-independent | The same algorithm can become a C, Python or Java program. It outlives any one language. |
| Easy to check | You can trace an algorithm by hand with test data (a dry run) and spot mistakes before any code exists. |
| Communication | Analysts, programmers and teachers can discuss an algorithm without everyone knowing the same language. |
| Reuse | A good algorithm (for example, finding the largest value) is used again in many programs. |
| Documentation | Later, someone maintaining the program can read the algorithm to understand what the code is meant to do. |
The cost of an error grows the later it is found. A wrong step caught while you write the algorithm costs a few seconds. The same mistake found after the program has been written, tested and handed over can cost days, or real money if a company relied on the wrong output.
Try it 1Be the computer: a literal-minded robot
The robot (orange arrow) understands only three instructions. Build an algorithm from them to get it to the coconut, then tap Run to watch it, or Step to run one instruction at a time. Try the vague instruction too, and see what happens.
Your algorithm:
Three lessons hide in that robot. First, the robot never guesses: if your third step is wrong, it walks into the rock. Second, the vague instruction “go to the coconut” is useless to it, even though a person would understand it at once. Third, there is usually more than one correct algorithm for the same problem (try reaching the Level 2 coconut by two different routes), but every correct one must be complete and in the right order.
Part 4: Programs
A program is a set of instructions written in a programming language that a computer can carry out (after it has been translated into machine code by a compiler or interpreter). In other words, a program is an algorithm expressed in a particular programming language, following that language’s exact rules (its syntax).
| Algorithm | Program | |
| Written in | Plain language, pseudocode or a flowchart | A programming language such as C |
| Audience | People (analysts, programmers, students) | A computer (and the people who maintain it) |
| Syntax rules | Flexible, as long as the meaning is clear | Strict: one missing semicolon and C will not compile |
| Can it run? | Not directly; it is traced by hand | Yes, after translation into machine code |
| Depends on a language? | No | Yes |
If you have already met C on this site, you know how fussy a compiler can be: Statements, Semicolons, and Whitespace: How the Compiler Reads Your Code shows how every statement must end in a semicolon. That fussiness is exactly why we sort out the logic first. When you write the program you want to be fighting only the syntax, not the logic and the syntax at the same time.
Part 5: Why develop the logic first?
The syllabus asks you to explain the need for developing the logic of a program, and describes algorithms as logically sequenced instructions. “Logic” here means the reasoning that connects input to output: which values are needed, which calculations use them, which decisions are made, and in what order. Three reasons stand out:
- Computers follow instructions literally and in order. They cannot reorder steps, fill in a missing step or guess what you meant. If the logic is wrong, the computer will faithfully produce the wrong answer.
- Steps depend on one another. An average cannot be calculated before the marks have been read; a total must be set to 0 before you start adding to it. Putting the steps in a logical sequence is part of solving the problem.
- Logic errors are the hardest errors to find. A syntax error is caught by the compiler. A logic error compiles cleanly, runs, and gives a believable but wrong answer. Planning the logic first, and tracing it with test data, is the best defence.
Worked example (an order error). Here is an algorithm for the average of three marks with two steps swapped:
1. Set total to 0 2. Set average to total / 3 3. Repeat 3 times: input mark, add mark to total 4. Output average
Every step is sensible on its own, but step 2 happens when total is still 0, so the output is always 0, whatever marks are typed. The C version of this mistake is shown in Part 6. Try it 2 lets you make, and fix, mistakes like this one.
Try it 2Logically sequenced instructions
Choose a problem. The steps of a correct algorithm are shown in a scrambled order. Use the arrows to reorder them, then tap Run to trace the algorithm with the sample input. For the two computer problems, Show as C turns your current order into C statements.
Part 6: From problem to program — one worked example
Here is the whole journey for the averages problem from Part 1, from problem statement to a C program. In later lessons you will learn each representation in more depth; for now, notice how each stage adds precision.
1. Problem and solution
Problem: teachers need students’ average marks produced quickly and accurately. Solution idea: a program reads how many marks there are, reads each mark, adds them up, and divides the total by how many there were.
2. Narrative (plain English)
First find out how many marks there are. Start a running total at zero. Then, for each mark, read it and add it to the total. When all the marks have been read, divide the total by the number of marks to get the average. Finally, display the total and the average.
3. Pseudocode
START
INPUT n
total ← 0
FOR i ← 1 TO n DO
INPUT mark
total ← total + mark
ENDFOR
average ← total / n
OUTPUT total, average
STOP
4. Flowchart
Dry run with n = 3 and marks 60, 75, 90:
| Step | i | mark | total | average |
| Start | 1 | – | 0 | – |
| After 1st mark | 2 | 60 | 60 | – |
| After 2nd mark | 3 | 75 | 135 | – |
| After 3rd mark | 4 | 90 | 225 | – |
| Loop ends (4 > 3) | 4 | 90 | 225 | 75 |
5. Program (C)
The same logic in C. The first number typed is n, followed by the marks. Each line of the pseudocode has a matching line of C: INPUT becomes scanf, ← becomes =, the FOR loop becomes a for statement, and OUTPUT becomes printf. The (double) makes C divide with decimals instead of throwing away the fraction.
#include <stdio.h>
int main(void)
{
int n, i, mark, total = 0;
double average;
scanf("%d", &n); /* how many */
printf("Marks read:");
for (i = 1; i <= n; i++) {
scanf("%d", &mark);
printf(" %d", mark);
total = total + mark;
}
average = (double) total / n;
printf("\nTotal: %d\n", total);
printf("Average: %.1f\n", average);
return 0;
}
Sample input: 3 60 75 90
Output:
Marks read: 60 75 90 Total: 225 Average: 75.0
And here is the order error from Part 5 written in C. It compiles with no warnings at all, which is the point: the compiler checks the syntax, not the logic.
#include <stdio.h>
int main(void)
{
int i, mark, total = 0;
double average;
/* BUG: average worked out too early */
average = total / 3.0;
for (i = 1; i <= 3; i++) {
scanf("%d", &mark);
total = total + mark;
}
printf("Total: %d\n", total);
printf("Average: %.1f\n", average);
return 0;
}
Sample input: 60 75 90
Output:
Total: 225 Average: 0.0
Try this: move the line average = total / 3.0; to just after the loop, recompile and run again with the same input. The average should now be 75.0. If you have not compiled C before, Your First C Program in Code::Blocks: Projects, Build, and Run walks you through creating, building and running a program in Code::Blocks.
Try it 3Problem, solution, algorithm or program?
Each card describes one of the four ideas, or asks why algorithms matter. Tap the best answer, then tap New question.
Summary
| Term | Meaning | Example (canteen) |
| Problem | The gap between the current state and the desired state. | The canteen cannot predict how many patties will be wanted. |
| Problem-solving | The process of finding and carrying out a way to close the gap. | Investigating sales, choosing a method, trying it out. |
| Solution | A method or plan that removes the gap. | Use the last four weeks’ sales to set each day’s order. |
| Algorithm | A finite, ordered sequence of clear, unambiguous steps that solves the problem. | Add the four sales figures for this weekday, divide by 4, add 10%, round up. |
| Program | The algorithm written in a programming language so a computer can run it. | A C program that reads the sales and prints tomorrow’s order. |
The logic is developed first because computers follow instructions literally and in sequence, steps depend on earlier steps, and logic errors are not caught by the compiler.
Review questions
1. Explain what is meant by a problem in the context of problem-solving with computers.
Show answer
A problem is the difference (gap) between the current situation and the desired situation. Solving it means finding a way to move from the current state to the desired state.
2. Write a problem statement for this situation: a youth club collects $20 dues from 60 members, but the treasurer keeps losing track of who has paid.
Show answer
For example: "The youth club treasurer cannot reliably tell which of the 60 members have paid their $20 dues, so some members are asked twice and others are missed. The club needs an accurate, up-to-date record of who has paid." (It names who, the current state and the desired state, and does not name a solution.)
3. Give TWO possible solutions to the youth club problem, one that uses a computer and one that does not.
Show answer
Non-computer: a printed register with a column to tick and initial when dues are paid. Computer: a spreadsheet or small program that records each payment and lists unpaid members.
4. Define the term algorithm.
Show answer
An algorithm is a finite, ordered sequence of clear, unambiguous steps that solves a problem or completes a task.
5. State TWO reasons why algorithms are important in the problem-solving process.
Show answer
Any two: they let the logic be planned and checked before coding; they are language-independent; they can be traced (dry run) to find errors early; they communicate the solution to others; they can be reused; they document what the program should do.
6. Distinguish between an algorithm and a program.
Show answer
An algorithm is a language-independent sequence of steps written for people (in narrative, pseudocode or a flowchart). A program is that algorithm written in a particular programming language, following its syntax, so that a computer can execute it.
7. Why is "Add a few more marks if the student worked hard" an unsuitable step for a computer algorithm?
Show answer
It is ambiguous: "a few" and "worked hard" have no exact meaning, so a computer cannot carry it out and different people would carry it out differently.
8. A student’s program compiles without errors but always prints an average of 0. Explain, with reference to the logic of the program, how this can happen.
Show answer
The program has a logic error, for example the average is calculated before the marks are read (while the total is still 0). The compiler only checks syntax, so the error is not detected. The steps must be in the correct logical sequence.
9. Explain the need for developing the logic of a computer program before coding it.
Show answer
Computers follow instructions literally and in order, so every step and its order must be worked out exactly. Steps depend on values produced earlier. Planning and tracing the logic first finds logic errors early, when they are cheapest to fix, and lets the programmer concentrate on syntax when coding.
Homework
- Choose a problem at your school or in your community. Write (a) the current state, (b) the desired state and (c) a two-sentence problem statement that does not mention any solution.
- For the same problem, list three possible solutions. For each, give one advantage and one disadvantage.
- Write a numbered algorithm (at least six steps) for topping up a prepaid phone credit at a shop. Swap with a friend: can they follow it without asking you a single question? Mark any step that is ambiguous.
- Complete Level 3 of Try it 1 with as few steps as you can. Write your algorithm down and explain why no shorter one works.
- Change
average.cso it also prints the highest mark. (Hint: keep a variablehighest, start it at the first mark, and update it inside the loop.)
Mastery quiz: Problems, Solutions, Algorithms and Programs
This 10-question quiz is separate from the short Quick quiz at the end of the lesson. Score 8/10 or higher to earn this lesson’s badge. Your best score is saved in this browser on this device.
Mastery quiz: Problems, Solutions, Algorithms and Programs
Your course badges: loading saved progress…
View badges
No course badges earned yet. Score 8/10 in a lesson quiz to earn its badge.
Saved in this browser on this device. Clearing browser data may remove your badges.
Answer all 10 questions. Earn this lesson’s badge at 8/10 or higher. Read the explanations, revisit the Try it activities and retry as often as you need. These are self-study badges, not formal grades.
Exam tips
Specimen Unit 1 Paper 02 (2021), Question 3(a). A short definition of an algorithm for two marks. Give the full idea in one sentence: a finite, ordered set of clear, unambiguous steps that solves a problem. "A set of instructions" on its own is too thin for full marks.
CAPE 2009 Unit 1 Paper 02, Question 3(a) also opened with a definition of an algorithm before moving on to constructs and a loop trace. The Go further box above links a worked answer on this site.
CAPE 2012 Unit 1 Paper 02, Question 3(a) asked about why algorithms are used. Strong answers give a reason and a consequence, for example: "an algorithm lets the logic be checked by a dry run before coding, so logic errors are found when they are cheapest to correct."
General advice: when a question asks you to explain or distinguish, write both sides. For "algorithm versus program", say what each is and how they differ (language-independent versus written in a programming language with strict syntax). When you write a problem statement, keep solutions out of it. More worked answers are on the CS Solutions page.
Previous: Module 1 • Lesson 16 – Processor Performance: Clock Speed, Cache, GPUs and Multi-Core. Next: Module 2 • Lesson 02 – Top-Down, Bottom-Up, Stepwise Refinement and Hierarchy Charts. See also: What is a problem? and The Importance of algorithms.
Syllabus link: CAPE Computer Science (CXC A19/U2/21), Problem-Solving with Computers (Unit 1, Module 2). Specific Objective 1: explain concepts related to problem-solving (problem-solving, problem, solution, algorithm and program; the algorithm as a problem-solving strategy, and its role and importance). Specific Objective 10: explain the need for developing the logic of a computer program.
Video
Optional video: What’s an algorithm? (TED-Ed, David J. Malan, YouTube). A short animated introduction that compares a person counting one at a time with smarter step-by-step methods.
You can also search YouTube for: "problem statement examples", "algorithm vs program", "logic errors vs syntax errors".
Try it 4Quick quiz
Tap an answer. All eight questions are self-checks on this lesson.
Updates
2026/12/01
- Updated the copyright line.
- Published. Previous/Next links and the mastery quiz links now use the full lesson addresses.
- Small script tidy-up for the site (no change to how the activities work).
2026/11/24
- Linked Previous/Next and the mastery quiz URLs to draft shortlinks (?p=ID), which will redirect to the permalink after publish.
- First version of the lesson.
© 2026 islandclass.org
