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 >
Wrap
C/C++ Source or Header
|
1995-09-18
|
496b
|
24 lines
// Get needed include files
#include <limits.h>
#include <iostream.h>
// Global error variable declaration
short ErrorCode;
unsigned short Add(unsigned short addend1, unsigned short addend2)
{
unsigned long sum = addend1 + addend2;
if (sum > USHRT_MAX)
ErrorCode = -1;
return (unsigned short) sum;
}
void main()
{
unsigned short Result = Add(12345, 54321);
if (ErrorCode == -1)
cout << "Overflow error!\n";
else
cout << "The answer is " << Result << "\n";
}