Module: Nested conditional statement. Difficult conditions


Problem

1/14

Nested conditional statement

Theory Click to read/hide

The blocks “if” and “otherwise” may include any other statements, including other nested conditional statements; while the else statement refers to the nearest previous if

Example
if ( A > 10 )
  if ( A > 100 )
    cout << "You have a lot of money.";
  else
    cout << "You have enough money.";
else
    cout << "You have not enough money.";
To make it easier to understand the program, all the blocks “if” and “otherwise” (together with the brackets enclosing them) are shifted to the right by 2-3 characters — such a record is called a “ladder” record
Recording "ladder" is a good form for any programmer!

Problem

Using the nested conditional operator, write a program that will display the word "YES" if the number entered from the keyboard is in the range from 20 to 40, and the word "NO" otherwise.

Complete the original program with the necessary conditions.

Please note that there are two else branches in the program - if any of the conditions is not met, the word NO must be displayed.