[previous_group] * [up] [next] [next_group]

The Five Steps

Understand the problem

Do a small example by hand

Write an algorithm for solving the problem

Translate the algorithm into a programming language (like C)

Our modules are:

Things to note about this code:

* The use of functions.
I have used functions to "hide" details of the modules implementing the program. Prototypes and descriptions for these functions are found in the header files, guess.h and play.h.
* While loops.
While loops are used in two places in the code:
In both cases, we began with the generic while loop algorithm:
     initialize loop condition
     while the condition is true
          do the body of the loop
          update the loop condition
and made it specific for the task at hand.
* Output formatting.
I have taken special care to make the output look nice. By inserting newlines ('\n'), and tabs ('\t') the output is easier to read. I did this as a last step - by trial and error.
These special characters in the format strings are called escape sequences. The complete set includes:
     \a     alert (bell)
     \b     backspace
     \f     formfeed
     \n     newline
     \r     carriage return
     \t     horizontal tab
     \v     vertical tab
     \\     backslash
     \?     question mark
     \'     single quote
     \"     double quote
     \ooo   octal number
     \xhh   hex number

* Use of macros.
I have used macros for all of the constants in the program, including things specified in the spec, such as the number of guesses, the range of numbers, etc. These macros are defined in the header files, guess.h and play.h.
These also include arbitrary valued macros to make my code more readable, such as values for WIN and LOSE or HI and LOW in play.h.
* A non-numeric macro, PICK in guess.h
This is also a new type of macro, a macro with arguments.

Test the program


[up] to Overview.

[next]