home *** CD-ROM | disk | FTP | other *** search
/ Using Visual C++ 4 (Special Edition) / Using_Visual_C_4_Special_Edition_QUE_1996.iso / ch13 / global.cpp < prev    next >
C/C++ Source or Header  |  1995-09-18  |  496b  |  24 lines

  1. // Get needed include files
  2. #include <limits.h>
  3. #include <iostream.h>
  4.  
  5. // Global error variable declaration
  6. short ErrorCode;
  7.  
  8. unsigned short Add(unsigned short addend1, unsigned short addend2)
  9. {
  10.     unsigned long sum = addend1 + addend2;
  11.     if (sum > USHRT_MAX)
  12.         ErrorCode = -1;
  13.     return (unsigned short) sum;
  14. }
  15.  
  16. void main()
  17. {
  18.     unsigned short Result = Add(12345, 54321);
  19.     if (ErrorCode == -1)
  20.         cout << "Overflow error!\n";
  21.     else
  22.         cout << "The answer is " << Result << "\n";
  23. }
  24.