What a program actually does
What is a program?
At the neighborhood repair workshop, someone counts donated tools. A program is a set of instructions a computer can carry out. Before writing those instructions in C, we can work out the steps on paper. A step-by-step method for a task is called an algorithm.
Suppose two visitors bring 2 tools and 3 tools today. The workshop needs today's total, not yesterday's.
- Start today's count at zero.
- Add the first donation: the count becomes 2.
- Add the second donation: the count becomes 5.
- Show the count when someone asks.
The donation numbers are input: data the program works with. The count is a value it remembers while it works. The displayed total is output: a result it sends out.
Why the order matters
If you add donations before resetting the count, you erase today's work. If you never reset it, yesterday's tools may be counted again. Correct instructions in the wrong order can still give a wrong answer.
At the start of the next day, repeat the steps with a fresh count of zero. Programs can repeat work and choose between actions; they do not always run every instruction just once. Later, you'll write those repetitions as loops and those choices as conditions.
For now, trace one more donation on paper: start with the current count of 5 and add 4 tools. The count becomes 9 without resetting to zero. The computer needs an instruction to update the remembered count, just as you did.