If statement
The if statement is also called a judgment statement, for example, whether it is correct or not, the ratio size, etc. Let's take a look at the exercise;
1. Start Geany
1) Click "Application-programming-Geany" in the menu to start Geany and create a c ++ source program;
2) Click the "file-save as" command in the menu and save the file to your own folder with "if" as the file name;
2. Enter the program code.
1) First, let's look at a traffic light. Enter a number. 1 indicates bright, 0 indicates off, the red light stops, and the green light goes ;;
2) In the following blue code area, enter the following code (press the Tab key to skip the grid, // The comment is next to it, you can skip it first );
Int hong = 0;
Cout <"input hong: (0 | 1 )";
Cin> hong;
If (hong = 1)
{
Cout <"ting"; // click the Tab key
}
Else // click the backspace key
{
Cout <"xing ";
}
3) The first section defines the variable and assigns the initial value,
The second part is a prompt and enter a number to the variable hong,
4) The third part is divided into two if and else parts. Either of them depends on the conditions in the brackets,
If the value of hong is 1, run cout <"ting"; otherwise, run the following line "cout <xing"