Chapter 4
Chapter 4
int main()
{
bool result;
result = 'a' < 'b';
cout << result << endl;
}
int main()
{
char character;
cout << (int) character;
// or
cout << int (character);
}
unary
binary
binary
• One-Way Selection
• Two-Way Selection
• Compound (Block of) Statements
• Multiple Selections
• Nested if
• Comparing if...else Statements with a
Series of if Statements
Example:
// outer if condition
if (num != 0) {
// inner if condition
if (num > 0) {
cout << "The number is positive." << endl;
}
// inner else condition
else {
cout << "The number is negative." << endl;
}
}
// outer else condition
else {
cout << "The number is 0" << endl;
}
C++ Programming: From Problem Analysis to Program Design, Fourth Edition 44
Comparing if…else Statements
with a Series of if Statements