[C language] 9-Selection structure of three major structures-3

1. Comprehensive examples

1.1 Example 1

Write a program to input a number from 1 to 7, and the output corresponds to the day of the week. It is
recommended to use Visio or similar software to draw a flow chart. When designing programs, especially in large-scale projects, software flow charts can help us analyze the structure and structural requirements of the program well. Writing programs according to the flow charts can make the written programs more organized.
The following figure is a flow chart for this example:
Insert image description here

illustrate:

  1. The software process needs to use rounded rectangles as the start box and end box to represent the start and end of the program.
  2. The rectangular frame represents a specific processing step or operation.
  3. Arrows represent the direction of the program
  4. The diamond box is a judgment box. The conditions for judgment should be filled in the judgment box, and the arrow pointed out needs to have a text explanation, such as whether the condition is true or not.

In this program, if you use ifstatements to write code, a diamond box should correspond to a ifstatement, and I added in the flow chart that if the entered number is not an integer between 1-7, the program should output an error message, Failure to handle user error input may cause the program to fail to run.
If the program can predict some incorrect inputs or incorrect usage methods in advance, it will greatly improve the stability of the program. This is also called the robustness of the program. In the future, everyone should also take into account the program's robustness when programming. Robustness
Below are 3 ways of writing to complete this program. Please experience the similarities and differences.

Guess you like

Origin blog.csdn.net/FuckerGod/article/details/131937439