了解计算机科学的基本概念 熟悉不同类型的编程语言了解典型C++程序的开发环境用C++编写简单的计算机程序使用简单输入与输出语句熟悉基本数据类型使用算术运算符了解算术运算符的优先级编写简单的判断语句
22
23 if(num1>num2)
24 cout<<num1<<" is greater than "<<num2<<endl;
25
26 if(num1<=num2)
27 cout<<num1<<" is less than or equal to "
28 <<num2<<endl;
29
30 if(num1>=num2)
31 cout<<num1<<" is greater than or equal to "
32 <<num2<<endl;
33
34 return 0; // 返回一个程序正常结束的标识
35 }
输出结果:
Enter two integers,and I will tll you
The relationships they satisfy: 3 7
3 is not equal 7
3 is less than 7
3 is less than or equal to 7
Enter two integers,and I will tell you
the relationships they satisfy:22 12
22 is not equal 12
22 is gretaer than 12
22 is greater than or equal to 12
Enter two integers,and I will tell you
the relationships they satisfy:7 7
7 is equal to 7
7 is less than or equal to 7
7 is greater than or equal to 7
图1.14 使用相等和关系运算符
编程技巧1.16
if语句中的缩排可以提高程序的可读性,突出结构体
编程技巧1.17
程序中一行只放一条语句
常见编程错误1.8
if语句的打件后面的右括号之后紧跟着分号通常是个逻辑错误(但不是语法错误)。分号使if结构体变成空的,不管打件是否为真,这个if结构都不进行任何操作。更糟糕的是,原先if结构体变成if结构后面的语句,不管条件如何总是执行,通常会使程序产生错误结果。