{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

06 Selection - Engineering101 Selection QuoteoftheDay...

Info iconThis preview shows pages 1–17. Sign up to view the full content.

View Full Document Right Arrow Icon
Click to edit Master subtitle style Engineering 101 Selection
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Quote of the Day - Confucius The essence of knowledge is, having it, to apply  it; not having it, to confess your ignorance.
Background image of page 2
Selection n So far we have discussed  sequence  and  iteration . n Selection  allows the execution of a portion  of your code depending on some condition.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Selection n Allows the selective execution of a portion  of your code depending on some condition. n Syntax in C++: if (condition)   statement_t else statement_f
Background image of page 4
Selection n Allows the selective execution of a portion  of your code depending on some condition. n Syntax in C++: if ( condition )   statement_t else statement_f The condition is similar to the while condition. It evaluates to true or false.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Selection n Allows the selective execution of a portion  of your code depending on some condition. n Syntax in C++: if ( condition )   statement_t else statement_f If the condition evaluates to true then statement_t is executed.
Background image of page 6
Selection n Allows the selective execution of a portion  of your code depending on some condition. n Syntax in C++: if ( condition )   statement_t else statement_f If the condition evaluates to false then statement_f is executed.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Selection n Allows the selective execution of a portion  of your code depending on some condition. n Syntax in C++: if ( condition )   statement_t else statement_f The statements can either be single line expressions or multiple expressions enclosed in braces.
Background image of page 8
Selection n Allows the selective execution of a portion  of your code depending on some condition. n Syntax in C++: if ( condition )   statement_t else statement_f The else can be entirely removed.
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Selection n Allows the selective execution of a portion  of your code depending on some condition. n Syntax in C++: if ( condition1 )   statement_t1 else if ( condition2 ) statement_t2 else statement_f Or you can add more else conditions in the form of ‘else if’.
Background image of page 10
Simple Example int x; cin >> x; if (x % 2 == 0)  cout << x << “is an even number” << endl; else cout << x << “is an odd number” << endl;
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Simple Example int x; cin >> x; if (x % 2 == 0)  cout << x << “is an even number” << endl; else cout << x << “is an odd number” << endl; x 14
Background image of page 12
Simple Example int x; cin >> x; if ( 14 % 2 == 0 cout << x << “is an even number” << endl; else cout << x << “is an odd number” << endl; x 14
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Simple Example int x; cin >> x; if ( 0 == 0 cout << x << “is an even number” << endl; else cout << x << “is an odd number” << endl; x 14
Background image of page 14
Simple Example int x; cin >> x; if (x % 2 == 0)  cout << x << “is an even number” << endl; else cout << x << “is an odd number” << endl; x 14 14 is an even number
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Simple Example int x; cin >> x; if (x % 2 == 0)  cout << x << “is an even number” << endl; else cout << x << “is an odd number” << endl; x 27
Background image of page 16
Image of page 17
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}