Sunday, March 12, 2017

C++ Part 18

A SINGLE STATEMENT FOR EACH ALTERNATIVE


if (Boolean_Expression)
Yes_Statement
else
No_Statement
If the Boolean_Expression evaluates to true, then the Yes_Statement is executed.
If the Boolean_Expression evaluates to false, then the No_Statement is executed.
Multi if-else Statement

if (Boolean_Expression_1)
Statement_1
else if (Boolean_Expression_2)
Statement_2
. . .
else if (Boolean_Expression_n)
Statement_n
else
Statement_For_All_Other_Possibilities

// EXAMPLE

if ((temperature < -10) && (day == SUNDAY))
cout << "Stay home.";
else if (temperature < -10) // and day != SUNDAY
cout << "Stay home, but call work.";
else if (temperature <= 0) // and temperature >= -10
cout << "Dress warm.";
else // temperature > 0
cout << "Work hard and play hard.";  

No comments:

Digital Design Part 3

4th→ assembler translates it to the machine language. 1.6 [20] <§1.6> Consider two diļ¬€erent implementations of the same instru...