Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 154 - CoreGPT(Podar)_Flipbook_C8
P. 154

    cout<< "The number is a two-digit number.";

                          }
                          else if(num >= 100 && num <= 999)
                          {
                              cout<< "The number is a three-digit number.";
                          }
                          else if(num >= 1000 && num <= 9999)
                          {
                              cout<< "The number is a four-digit number.";
                          }
                          else if(num >= 10000 && num <= 99999)
                          {
                              cout<< "The number is a five-digit number.";
                          }
                          else
                          {
                              cout<< "The number is not between two and five digits.";
                          }
                          getch();

                      }
                                           Enter a number: 24576
                                           The number is a five-digit number.

                                           Enter a number: 346
                                           The number is a three-digit number.

                                           Enter a number: 123456
                                           The number is not between two and five digi
                      The switch Statement

                      The switch statement is a control structure that provides a more efficient way to replace multiple
                      if…else…if statements when testing a single expression against multiple values. The syntax of
                      the switch statement is:

                      switch(expression)
                      {

                      case value1:
                      // Statements;
                          break;

                      case value2:
                      // Statements;
                          break;

                    152     Premium Edition-VIII

| 149 150 151 152 153 154 155 156 157 158 159 |