home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Info / TeachU14 / SAMS / Code / Day02 / scope.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-08  |  864 b   |  39 lines

  1. //---------------------------------------------------------------------------
  2. #include <condefs.h>
  3. #include <conio.h>
  4. #include <iostream.h>
  5. #pragma hdrstop
  6.  
  7. //---------------------------------------------------------------------------
  8. int x = 20;
  9. void CountLoops(int);
  10.  
  11. int main(int, char**)
  12. {
  13.   int x = 40;
  14.   int i = 0;
  15.   cout << "In main program x = " << x << endl;
  16.   bool done = false;
  17.   while (!done) {
  18.     int x;
  19.     cout << endl << "Enter a number (-1 to exit): ";
  20.     cin >> x;
  21.     if (x != -1) {
  22.       cout << endl << "In while loop x = " << x;
  23.       CountLoops(++i);
  24.     }
  25.     else
  26.       done = true;
  27.   }
  28.   cout << "Global x = " << ::x << endl;
  29.   cout << endl << "Press any key to continue...";
  30.   getch();
  31.   return 0;
  32. }
  33. void CountLoops(int x)
  34. {
  35.   cout << ", While loop has executed "
  36.     << x << " times" << endl;
  37. }
  38.  
  39.