C + + Basic Tutorials-if Statements

Source: Internet
Author: User

If statement

If statements are also called judgment statements, such as whether it is correct, larger than the size, and so on, let's look at an exercise;

1, start Geany

1 point Menu "application-programming-geany" Start Geany, create a new C + + source program;

2 Point Menu "file-Save as" command, to "if" as the filename, save the file to its own folder;

2, input program code

1 first to see a judge of the traffic lights, enter a number, 1 for light, 0 for the kill, red stop, Green Line;

2 in the Blue Code area below, enter the following code (press TAB to jump lattice,//followed by comments, you can not enter);

int: 0;

cout << "Input: (0|1)";

CIN >>;

if (+ = 1)

{

cout << "ting";//press the TAB key

}

else//Click Backspace key

{

cout << "Xing";

}

3 The first paragraph is to define the variable and give the initial value,

The second paragraph is the hint and enter a number for the variable,

4 The third paragraph is divided into two if and else, is two choose one, choose which one according to the conditions in parentheses,

If the value is 1, run cout << "Ting", otherwise run the following line "cout << Xing"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.