In the first line of the program, we include the iostream header file (Input/Output streams library). This is essential because later in the program we will want the ability to write to the screen (cout) and read input data from the keyboard (cin).
In the second line, we inform the compiler that we will be using names defined in the std namespace (specifically: cin, cout, and endl). If we didn't do this, it would be necessary to use the longer form of qualified names (std::cin, std::cout, std::endl).
In C++, a program begins with the execution of the main function. In our example, this is the program's only function. Line 3 contains the start of the main function definition, which marks the beginning of our algorithm's execution (START block (1)).
In the following line, we declare two variables, a and b, which we will be using shortly. In C++, variables can be declared anywhere before their use, which is why we don't immediately declare the variable x, which might not be needed at all.
Lines 5 to 8 implement the Input/Output operation (2), where the input data—the coefficients a and b of the equation—are retrieved.
The conditional statement on line 9 is the Decision block (3) from our algorithm. The statement checks whether the coefficient a is equal to 0. If the condition is met, the instructions contained in lines 10 through 14 are executed (corresponding to the Decision block (4) and Input/Output blocks (5) and (6) in the algorithm). If the condition is not met, the instruction following the keyword else is executed; in our case, this is a compound statement enclosed in curly braces {} between lines 14 and 18. First, on line 15, we declare the variable x (now we know we'll need it), then on line 16, we calculate the solution to the equation x=−b/a (Operation block (7)), and finally, on line 17, we output the received result (Input/Output block (8)).
The instructions on lines 19-21 have no relation to the execution of our algorithm. They serve to pause the program until any character is entered and the Enter key is pressed, which prevents the program window from closing immediately.
The closing curly brace } on line 22 ends the main function and, consequently, the execution of the entire program (Stop block of the algorithm (9)).
