Page 50 - Modular_V2.0_C++_Flikpbook
P. 50

else
                      {
                          cout<< "The number is not between two and five digits.";
                      }
                      getch();

                  }
                                          DOSBox 0.74, Cpu speed: max 100% cycles,
                                       Enter a number: 24576
                                       The number is a five-digit number.


                                          DOSBox 0.74, Cpu speed: max 100% cycles,
                                       Enter a number: 346
                                       The number is a three-digit number.


                                          DOSBox 0.74, Cpu speed: max 100% cycles,
                                       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;

                       case value3:
                       // Statements;

                           break;
                       default:
                       // Statements for unmatched cases;

                       }
                  This syntax shows how the switch statement checks for a match among multiple cases and uses
                  break to stop execution after a match is found. If no case matches, the default case runs.



                   48
                          Touchpad MODULAR (Ver. 2.0)
   45   46   47   48   49   50   51   52   53   54   55