What programming is: turning a problem into instructions
Programming is the work of expressing a solution as instructions precise enough for a computer to carry out. Before learning C++ punctuation, learn how to describe a task unambiguously.
Prerequisites: No prior programming or C++ knowledge is required. This lesson starts with everyday problem-solving and introduces the basic vocabulary used throughout the course.
Learning objectives
- Define program, input, output, and algorithm in plain language.
- Turn a small everyday task into ordered, checkable instructions.
- Explain why a computer needs more precision than a person does.
Start with a problem, not with code
Suppose a school club wants to show a visitor three preparation steps: pack a notebook, charge a laptop, and bring an ID card. The human problem is simple: communicate the steps in the right order. A program is a written set of instructions that tells a computer how to perform a task. The task may be displaying text, calculating a bill, sorting records, or controlling a device.
The information a program receives is its input. The result it produces is its output. An algorithm is a finite, ordered method for solving a kind of problem. For now, think of it as a carefully written recipe—not necessarily a food recipe.
Problem: tell a visitor what to bring Input: the three agreed preparation steps Algorithm: show step 1, then step 2, then step 3 Output: a readable checklist
Why precision matters
Humans fill in missing detail from context. If someone says “make tea,” you infer a cup, water, and a safe temperature. A computer does not make those everyday inferences. It follows the instructions represented by the program and its environment. If an important condition is missing, the program cannot reliably invent the intended one.
Imagine a robot instructed only to “put the book on the shelf.” Which book? Which shelf? What if the shelf is full? People might ask a question; a program must either include a rule for such cases or deliberately report that it cannot proceed.
Plan before translating into C++
Write a small algorithm in ordinary language first:
- Display “Pack your notebook.”
- Display “Charge your laptop.”
- Display “Bring your ID card.”
This algorithm has a clear order and a visible result. It is also easy to test: compare the three displayed lines with the three intended steps. Later, programs will use choices and repetition; beginning with a straight sequence keeps one new idea at a time.
A first C++ representation
You do not need to memorize this code yet. Use it to see that code is a precise written version of the plan.
#include <iostream>
int main() {
std::cout << "Pack your notebook.\n";
std::cout << "Charge your laptop.\n";
std::cout << "Bring your ID card.\n";
}Code, line by line
#include <iostream>makes the declarations for standard input/output streams available to this source file. You will examine this more closely later.- The blank line is for people reading the code; it does not change the program’s meaning.
int main() {begins the main function. In an ordinary hosted C++ program, execution reaches this function after program startup.- Each
std::coutline sends text to standard output. The quoted text is a string literal: characters written directly in the source code. \nrepresents a newline character, so the next output begins on a new line.- The closing brace
}ends the function body.
What happens when it executes
After the source code has been translated into a runnable program (the next lessons explain that translation), the operating system starts the program. In the function body, the first output statement is evaluated, then the second, then the third. For this straight-line example, there is no decision or loop to change that order. The text is sent to the program’s standard output destination, commonly a terminal window.
start main ↓ write first message ↓ write second message ↓ write third message ↓ finish main
The C++ standard specifies program behavior using an abstract model; a real processor may perform low-level work differently as long as the observable behavior required by the language rules is preserved.
Common beginner mistakes
- Starting with syntax instead of a goal: before typing, state what input, output, and steps the program needs.
- Leaving a step vague: “handle errors” is not an instruction until you say which error and what response is expected.
- Assuming code can infer intent: a program follows expressed rules. Test an example that exposes a missing rule.
- Changing several ideas at once: when learning, change one line and observe one effect.
Practical exercises
- Write an ordinary-language algorithm that displays a three-step morning study routine. Make every step observable.
- For a program that converts minutes to seconds, list the input, output, and the calculation in one sentence each. Do not write C++ yet.
- Change the three messages in the example to instructions for submitting an assignment. Compile and run it when a compiler is available.
- Find one vague instruction in your algorithm and rewrite it so that two different readers would be likely to do the same thing.
Show sample exercise solutions
- One clear routine could be: (1) open the study planner, (2) choose one subject, (3) set a 25-minute timer, (4) study the selected topic until the timer ends, and (5) write down one question to review. Other answers are valid if each step is observable and ordered.
- Input: a number of minutes. Output: the equivalent number of seconds. Calculation: multiply the input by 60.
- For example, replace the three string literals with
"Open the assignment brief.\n","Complete the required files.\n", and"Submit the files before the deadline.\n". The exact messages may differ, but each should describe one visible action. - Instead of “prepare for the exam,” write “open the syllabus, list the three topics to revise, solve five practice questions for each topic, and mark every incorrect answer for review.” This gives readers actions they can check.
Assessment: check your understanding
1. What is the difference between input and output?
Answer: Input is information supplied to a program; output is information or an action produced by it. Why: A temperature-reading program may receive a measurement as input and display a warning as output.
2. Is an algorithm always C++ code?
Answer: No. Why: An algorithm is a method for solving a problem; C++ is one way to express such a method precisely for a computer.
3. Why might “sort the records” be an incomplete instruction?
Answer: It does not say which field determines the order or what to do with equal values. Why: A usable program needs rules for choices that affect the result.
4. In the example, what makes the output order predictable?
Answer: The three output statements are evaluated sequentially in the function body. Why: No conditional or loop changes their order.
5. Does a computer need to understand the human purpose of the checklist to show it?
Answer: No. Why: It needs a correctly translated program that specifies the output operations; the human purpose motivated the design but is not required for this execution.
Revision summary
Programming begins with a problem and a precise plan. A program consumes input, follows an algorithm, and produces output. C++ is not the plan itself; it is a language we will use to represent the plan in a form a toolchain can translate and run.
References
- cppreference: C++ basic concepts
- Working draft of the C++ standard: abstract machine
- Harvard CS50x 2026: Computer Science and Problem Solving (input, output, algorithms, and pseudocode) — supplementary introductory computer-science teaching material.