Sams Teach Yourself C++ in 21 Days
8: 9: int myAge = 39; // initialize two integers 10: int yourAge = 39; 11: cout << “I am: “ << myAge << “ year ...
Creating Expressions and Statements 77 4 Understanding Operator Precedence ..................................................... ...
Nesting Parentheses .............................................................................................. For complex e ...
Creating Expressions and Statements 79 4 The Nature of Truth ................................................................... ...
The six relational operators are equals (==), less than (<), greater than (>), less than or equal to (<=), greater than ...
Creating Expressions and Statements 81 4 The expression in the parentheses can be any expression, but it usually contains one of ...
14: cin >> YankeesScore; 15: 16: cout << “\n”; 17: 18: if (MetsScore > YankeesScore) 19: cout << “Let’s Go ...
Creating Expressions and Statements 83 4 Note that if the initial Yankees’ score is higher than the Mets score, the ifstatement ...
Putting the initial brace after the condition and aligning the closing brace under the ifto close the statement block: if (expr ...
Creating Expressions and Statements 85 4 6: using std::cout; 7: using std::cin; 8: 9: int firstNumber, secondNumber; 10: cout &l ...
Advanced ifStatements .................................................................................. It is worth noting that ...
Creating Expressions and Statements 87 4 LISTING4.6 A Complex, Nested ifStatement 1: // Listing 4.6 - a complex nested 2: // if ...
If the first ifis true, the block of code beginning on line 22 is executed, and a second if statement is tested on line 23. This ...
Creating Expressions and Statements 89 4 Enter a number less than 10 or greater than 100: 20 Less than 10, Thanks! The programme ...
14: std::cout << “More than 100, Thanks!\n”; 15: } 16: else // fixed! 17: std::cout << “Less than 10, Thanks!\n”; 18 ...
Creating Expressions and Statements 91 4 Using the Logical Operators............................................................ ...
Note that the logical ORis two ||symbols. A single |symbol is a different operator, which is discussed on Day 21. The Logical NO ...
Creating Expressions and Statements 93 4 It might be that the programmer wanted this expression to evaluate true if both xand y ...
These two statements also are equivalent: if (!x) // if x is false (zero) if (x == 0) // if x is zero The second statement, howe ...
Creating Expressions and Statements 95 4 15: 16: if (x > y) 17: z = x; 18: else 19: z = y; 20: 21: cout << “After if te ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf