home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C03 / Menu.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  1.5 KB  |  59 lines

  1. //: C03:Menu.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Simple menu program demonstrating
  7. // the use of "break" and "continue"
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. int main() {
  12.   char c; // To hold response
  13.   while(true) {
  14.     cout << "MAIN MENU:" << endl;
  15.     cout << "l: left, r: right, q: quit -> ";
  16.     cin >> c;
  17.     if(c == 'q')
  18.       break; // Out of "while(1)"
  19.     if(c == 'l') {
  20.       cout << "LEFT MENU:" << endl;
  21.       cout << "select a or b: ";
  22.       cin >> c;
  23.       if(c == 'a') {
  24.         cout << "you chose 'a'" << endl;
  25.         continue; // Back to main menu
  26.       }
  27.       if(c == 'b') {
  28.         cout << "you chose 'b'" << endl;
  29.         continue; // Back to main menu
  30.       }
  31.       else {
  32.         cout << "you didn't choose a or b!"
  33.              << endl;
  34.         continue; // Back to main menu
  35.       }
  36.     }
  37.     if(c == 'r') {
  38.       cout << "RIGHT MENU:" << endl;
  39.       cout << "select c or d: ";
  40.       cin >> c;
  41.       if(c == 'c') {
  42.         cout << "you chose 'c'" << endl;
  43.         continue; // Back to main menu
  44.       }
  45.       if(c == 'd') {
  46.         cout << "you chose 'd'" << endl;
  47.         continue; // Back to main menu
  48.       }
  49.       else {
  50.         cout << "you didn't choose c or d!" 
  51.              << endl;
  52.         continue; // Back to main menu
  53.       }
  54.     }
  55.     cout << "you must type l or r or q!" << endl;
  56.   }
  57.   cout << "quitting menu..." << endl;
  58. } ///:~
  59.