home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tyc / list13_6.c < prev    next >
C/C++ Source or Header  |  1993-10-16  |  850b  |  43 lines

  1.  /* Demonstrates the switch statement correctly. */
  2.  
  3.  #include <stdio.h>
  4.  
  5.  main()
  6.  {
  7.      int reply;
  8.  
  9.      puts("Enter a number between 1 and 5, 0 to exit:");
  10.      scanf("%d", &reply);
  11.  
  12.      switch (reply)
  13.      {
  14.          case 1:
  15.              {
  16.              puts("You entered 1.");
  17.              break;
  18.              }
  19.          case 2:
  20.              {
  21.              puts("You entered 2.");
  22.              break;
  23.              }
  24.          case 3:
  25.              {
  26.              puts("You entered 3.");
  27.              break;
  28.              }
  29.          case 4:
  30.              {
  31.              puts("You entered 4.");
  32.              break;
  33.              }
  34.          case 5:
  35.              {
  36.              puts("You entered 5.");
  37.              break;
  38.              }
  39.          default:
  40.              puts("Out of range, try again.");
  41.      }
  42.  }
  43.