previous | start | next

## From Pseudocode to Code

- Break the problem into sub-tasks and design subprograms.

  >     /**
  >        Turns a digit into its English name
  >        @param n an integer between 1 and 9
  >        @return the name of n ("one" ... "nine")
  >     */
  >     string digit_name(int n);

  >     /**
  >        Turns a number between 10 and 19 into its English name.
  >        @param n an integer between 10 and 19
  >        @return the name of n ("ten"..."nineteen")
  >     */
  >     string teen_name(int n);

  >     /**
  >        Gives the English name of a multiple of 10
  >        @param n an integer between 2 and 9
  >        @return the name of 10 * n ("twenty"..."ninety")
  >     */
  >     string tens_name(int n);

- What is missing?
  - For hundreds, we show the digit name then write "hundreds".
  - For 100 - 999, we can put calls to functions above together to write number.
  - For numbers over 1,000, we call functions above to write the number of thousands, print "thousands", then call the above functions again to write the rest of the number.

previous | start | next