C++ Programing Basics - Part 2
C++ Programing Basics - Part 2
Part 2
Control Flows
“Would you tell me, please,
which way I ought to go from
here?”
driverAge
if (driverAge < 26) < 26?
{
premiumDue += 100
premiumDue += 100;
cout << “Young driver.\n”;
} display Young driver
The Single-Alternative if
If we do not “group” the statements or block them with
curly braces, the C++ compiler will interpret the code
differently
driverAge
< 26?
if (driverAge < 26)
premiumDue += 100; premiumDue += 100
cout << “Young driver.\n”;
display
display Male
Female
if (a > b)
++a;
else
b += 10;
a = 0;
1. If, when this code segment starts, a is 10 and b is 7, then
when it ends, a is 11.
A little review please …
Consider the following code segment:
if (a > b)
++a;
else
b += 10;
a = 0;
2. If, when this code segment starts, a is 2 and b is 4, then
when it ends, b is 14.
A little review please …
Consider the following code segment:
if (a > b)
++a;
else
b += 10;
a = 0;
3. If, when this code segment starts, a is 12 and b is 9, then
when it ends, a is 10.
Using a Nested if
A nested if structure can reside within either or both of the
if and else clauses of its containing if structure.