Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
One way to help in debugging programs is to create output for every input and every calculation along the way.
This, however, makes for a lot of output and users may not want to see all of that output unless desired.
One way to handle this is to use a variable to turn the display of text on and off.
2. Debuggers
One can use an IDE (Integrated Development Environment) , such as Visual Studio, Eclipse, etc., that allows one to insect variables while the program is running.
However, this method does not always scale up to larger more complex programs.
The method presented here works for all types of programming systems.
3. Diagnostic output
The program inputs an integer variable (without prompt) that determines whether diagnostic output is shown according to the following values.
If 0, no extra output is shown, just the final results (no condition necessary)
If 1, output from processing and the final result, are shown (condition "greater than zero").
If 2, all output, including prompts and echo, is shown (condition "greater than one").
4. Measurement units
The measurement units are on the second line. Note that, in C, due to limited string handling capabilities, a "\n" is needed on the previous input statement to "eat" the newline in the input.
Here is the C code.
5. Examples of input and output
Here are some examples of input and output for the above program code.
Here is an example input.
For the above example input, here is the expected output.
Here is an example input.
For the above example input, here is the expected output.
Here is an example input.
For the above example input, here is the expected output.
6. Wrong way
Below is the wrong way to do debugging with output. Do not write a separate program for each debugging case, as in the following program.
The following program consists of repeated code - code for each of the show cases. Do not do debugging output in this manner! Use the above example.
Here is the C code.
7. Examples of input and output
Here are some examples of input and output for the above program code.
Here is an example input.
For the above example input, here is the expected output.
Here is an example input.
For the above example input, here is the expected output.
Here is an example input.
For the above example input, here is the expected output.
8. Assumptions
Do not change show1 > 1 to show == 2 as one may want to add a show1 value of 3, 4, etc. in the future.