Program design

Before coding, design the program first.

This sounds obvious, which means I will probably ignore it and then suffer.

Simple process#

  1. Define the goal of the program.
The program should read two numbers.
  1. Define requirements, meaning what the program should do.
The user enters numbers.
The program calculates the result.
The program prints the result.
  1. Break a hard problem into smaller problems.
calculator
- get first number
- get operation
- get second number
- calculate result
- print result
  1. Turn those smaller parts into functions.
getUserInput();
getMathematicalOperation();
calculateResult();
printResult();

This fits the rule that a function should do one specific thing.

  1. Decide the order of actions.
input -> calculation -> output
  1. Start with main() and commented function calls.
int main()
{
    // getUserInput();
    // getMathematicalOperation();
    // calculateResult();
    // printResult();

    return 0;
}
  1. Implement functions one by one.
prototype -> body -> test

Do not write the whole program at once.

Start with a simple working version.

Do not improve the first version too early.

At the beginning, write for readability, not performance.