Either the if-true statement or the if-false statement or both
may be embedded if
statements. Accordingly, another
solution to the temperature-testing problem looks like this:
#includemain ( ) { int temperature; cin >> temperature; if (temperature < 25) cout << "It is too cold!" << endl; else if (temperature > 50) cout << "It is too warm!" << endl; } --- Data --- 55 --- Result --- It is too warm!
Note that the first if
statement's if-false statement is, itself, an
embedded if
statement.
This embedded if
statement is executed only if the
temperature is not less than 25°F. If the
temperature is between 25°F and 50°F, nothing
is displayed.